Implemented cutscenes and mating

This commit is contained in:
Richard Ott
2018-09-01 18:54:44 +02:00
parent b6ea22e42b
commit e274f7a368
24 changed files with 1046 additions and 21 deletions

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CutscenePlayer : MonoBehaviour {
public Sprite[] theSprites;
public Image theBase;
public float speed = 1.0f;
private float TUNS = 0.0f;
private int i = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (i < theSprites.Length + 1) {
if (Time.time > TUNS)
{
i += 1;
if(i < theSprites.Length)
theBase.sprite = theSprites[i];
TUNS = Time.time + speed;
}
}
else
{
this.gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 719609795ac17cf44ae9bbe0f5137724
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,209 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LurchMovement : MonoBehaviour {
[Header("Mouse")]
[Range(0.01f, 4.0f)]
public float mouseSensitivity;
public bool invertMouse;
public bool lockMouse;
private float yaw = 0.0f;
private float pitch = 0.0f;
[Header("Smooth Follow")]
[Range(0.1f, 2)]
public float speed;
private Vector3 velocity = Vector3.zero;
[Header("Lurch")]
public Transform theLurch;
private Rigidbody lurchBody;
[Header("Jump Charge")]
public float maxJumpForce;
private float currentJumpForce;
public float forceIncreaseSpeed;
public Color normalColor;
public Color fullyChargedColor;
private Color lerpedColor;
public Vector3 normalSize;
[Range(0.1f, 1.0f)]
public float chargedSizeModifier;
private Vector3 chargedSize;
private Vector3 currentSize;
static float t = 0.0f;
[Header("Jump n Stick")]
public bool canStick;
[SerializeField]
private float cooldown;
[Header("Gliding")]
public bool canGlide;
private Vector3 glideSize;
[Range(1.0f, 10.0f)]
public float glideForce;
private void Start()
{
lurchBody = theLurch.GetComponent<Rigidbody>();
normalSize = theLurch.transform.localScale;
chargedSize = theLurch.transform.localScale * chargedSizeModifier;
glideSize = new Vector3(normalSize.x, normalSize.y * 0.5f, normalSize.z);
}
void Update()
{
theLurch.rotation = Quaternion.Euler(0, transform.eulerAngles.y, 0);
theLurch.GetComponent<Renderer>().material.color = lerpedColor;
theLurch.transform.localScale = currentSize;
MouseControl();
JumpControl();
SmoothFollow();
Gliding();
}
void MouseControl()
{
float mouseInputX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseInputY;
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
if (!invertMouse)
{
mouseInputY = Input.GetAxis("Mouse Y") * mouseSensitivity;
}
else
{
mouseInputY = -Input.GetAxis("Mouse Y") * mouseSensitivity;
}
yaw += mouseInputX;
pitch -= mouseInputY;
if (lockMouse)
{
Cursor.lockState = CursorLockMode.Locked;
}
else
{
Cursor.lockState = CursorLockMode.None;
}
}
void SmoothFollow()
{
Vector3 targetPosition = theLurch.TransformPoint(new Vector3(0, 0, 0));
// Smoothly move the camera towards that target position
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, speed);
}
void JumpControl()
{
if (Input.GetButton("Fire1") && currentJumpForce < maxJumpForce)
{
currentJumpForce += forceIncreaseSpeed;
lerpedColor = Color.Lerp(normalColor, fullyChargedColor, t);
if (t < 1.0f)
{
t += 2 * Time.deltaTime;
}
currentSize = Vector3.Lerp(currentSize, chargedSize, Time.deltaTime * 1.5f);
}
else if(!Input.GetButton("Fire1"))
{
lerpedColor = normalColor;
t = 0.0f;
currentSize = normalSize;
}
if (cooldown > 0.0f)
{
cooldown -= Time.deltaTime;
currentJumpForce = 0.0f;
}
if (Input.GetButtonUp("Fire1")) {
cooldown = 0.5f;
lurchBody.isKinematic = false;
lurchBody.AddForce(theLurch.forward * currentJumpForce, ForceMode.Impulse);
lurchBody.AddForce(theLurch.up * currentJumpForce, ForceMode.Impulse);
}
else if (LurchOnGround() && Time.time > cooldown)
{
lurchBody.isKinematic = true;
}
else if (!LurchOnGround() && Time.time > cooldown && !AmSticking())
{
currentJumpForce = 0.0f;
}
}
void Gliding()
{
if (canGlide && !lurchBody.isKinematic && Input.GetButton("Fire1") &&!LurchOnGround())
{
Debug.Log("Ich kann jetzt gleiten");
theLurch.transform.localScale = glideSize;
lurchBody.AddForce(theLurch.forward * glideForce);
lurchBody.AddForce(theLurch.up * 0.08f, ForceMode.Impulse);
}
if (!Input.GetButton("Fire1"))
{
theLurch.transform.localScale = currentSize;
}
}
public bool LurchOnGround()
{
RaycastHit hit;
if (Physics.Raycast(theLurch.position, Vector3.down, out hit, 0.36f) && cooldown <= 0.0f)
{
return true;
}
if (AmSticking())
{
return true;
}
return false;
}
bool AmSticking()
{
if (canStick) {
RaycastHit hit;
if (Physics.Raycast(theLurch.position, theLurch.forward, out hit, 1.4f))
{
return true;
}
if (lurchBody.isKinematic)
{
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9a548db4f33b8a24aa4ebca81f61e6dd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,133 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LurchRespawn : MonoBehaviour {
//Spawnpoints
[SerializeField]
private List<GameObject> respawnPoints = new List<GameObject>();
private GameObject lastRespawnPoint;
private int lastRespawnPointIndex;
//Refs
[SerializeField]
private Transform lowerBounds;
//ExtRefs
[SerializeField]
private GameObject lurch;
private LurchMovement compLurchMovement;
//States
private bool offGround = false;
private Vector3 lastGroundPos;
//Settings
[Header("Settings")]
[SerializeField]
[Tooltip("Update the spawnpoint every n frames")]
private int UpdateFrequenzy = 15;
[SerializeField]
private float maxFallDist = 100;
[SerializeField]
private KeyCode respawnKey = KeyCode.R;
void Start () {
if (respawnPoints.Count == 0)
{
this.enabled = false;
throw new System.Exception("No respawn points assigned");
}
compLurchMovement = gameObject.GetComponent<LurchMovement>();
lastGroundPos = lurch.transform.position;
lastRespawnPoint = respawnPoints[0];
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(respawnKey))
{
RespawnLurch("Player respawned");
}
if(!offGround)
{
if(!compLurchMovement.LurchOnGround())
{
offGround = true;
lastGroundPos = lurch.transform.position;
}
} else
{
if (compLurchMovement.LurchOnGround())
{
offGround = false;
float fallDist = Vector3.Distance(lurch.transform.position, lastGroundPos);
if (fallDist > maxFallDist)
{
//We fell too far
RespawnLurch("Lurch fell too far");
}
lastGroundPos = lurch.transform.position;
}
}
if(Time.frameCount % UpdateFrequenzy == 0)
{
UpdateRespawnPoint();
}
if (Time.frameCount % UpdateFrequenzy * 2 == 0)
{
CheckBounds();
}
}
private void CheckBounds()
{
if(transform.position.y < lowerBounds.position.y)
{
RespawnLurch("Lurch went out of bounds");
}
}
private void UpdateRespawnPoint()
{
float nextPointDist;
float lastPointDist = Vector3.Distance(transform.position, lastRespawnPoint.transform.position);
for (int i = lastRespawnPointIndex; i < respawnPoints.Count; i++)
{
nextPointDist = Vector3.Distance(transform.position, respawnPoints[i].transform.position);
if (nextPointDist < lastPointDist)
{
lastRespawnPoint = respawnPoints[i];
lastRespawnPointIndex = i;
}
}
}
public void RespawnLurch(string message = "Lurch respawned")
{
Debug.LogWarning("Lurch respawned: " + message);
lurch.transform.position = lastRespawnPoint.transform.position;
}
private void OnDrawGizmos()
{
for(int i = 0; i < respawnPoints.Count; i++)
{
if(respawnPoints[i] == lastRespawnPoint)
{
Gizmos.DrawIcon(respawnPoints[i].transform.position, "RespawnActive.png");
} else if (i < lastRespawnPointIndex)
{
Gizmos.DrawIcon(respawnPoints[i].transform.position, "RespawnInactive.png");
} else
Gizmos.DrawIcon(respawnPoints[i].transform.position, "Respawn.png");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 167337a6a977deb408440dbf31acb6c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MateMate : MonoBehaviour {
public bool mateStick;
public bool mateGlide;
public bool mateGlow;
public GameObject cutscene;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
private void OnTriggerEnter(Collider other)
{
if (other.transform.root.GetComponentInChildren<LurchMovement>())
{
if(mateStick)
other.transform.root.GetComponentInChildren<LurchMovement>().canStick = true;
if(mateGlide)
other.transform.root.GetComponentInChildren<LurchMovement>().canGlide = true;
if(mateGlow)
//other.transform.root.GetComponentInChildren<LurchMovement>().canGlide = true;
cutscene.SetActive(true);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 70076831801618547a292c354b3bba38
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: