mirror of
https://github.com/ConjureETS/MeltedBananasOJam2016.git
synced 2026-03-24 02:21:06 +00:00
Finished implementation of Slowmo
This commit is contained in:
parent
2c70709305
commit
368ac6ef80
@ -1,33 +1,47 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
public class PlayerMovement : MonoBehaviour {
|
public class PlayerMovement : MonoBehaviour
|
||||||
|
{
|
||||||
public float speed = 0f;
|
public float speed = 0f;
|
||||||
public float turn = 0f;
|
public float turn = 0f;
|
||||||
|
|
||||||
public Rigidbody characterRigidBody;
|
public Rigidbody characterRigidBody;
|
||||||
|
|
||||||
|
// Boost
|
||||||
public float boostFactor = 1f;
|
public float boostFactor = 1f;
|
||||||
public float seconds;
|
public float seconds;
|
||||||
float initialTime;
|
float boostDeadline;
|
||||||
bool SpeedBoostTimerStart;
|
bool SpeedBoostTimerStart;
|
||||||
//private Rigidbody rb;
|
// Slow motion
|
||||||
|
public float timeFactor = 0.2f;
|
||||||
|
public float duration = 5.0f;
|
||||||
|
float slowmoDeadline;
|
||||||
|
private bool SlowmoTimerStart = false;
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update () {
|
void FixedUpdate()
|
||||||
|
{
|
||||||
|
SpeedBoostTimer(seconds);
|
||||||
|
SlowmoTimer(duration);
|
||||||
|
ManageMovement();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ManageMovement()
|
||||||
|
{
|
||||||
|
|
||||||
Vector3 fowardVector = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z);
|
Vector3 fowardVector = new Vector3(Camera.main.transform.forward.x, 0, Camera.main.transform.forward.z);
|
||||||
if (Input.GetAxis("Vertical")>0)
|
if (Input.GetAxis("Vertical") > 0)
|
||||||
{
|
{
|
||||||
characterRigidBody.velocity = ( fowardVector * speed * boostFactor * Time.deltaTime);
|
characterRigidBody.velocity = (fowardVector * speed * boostFactor * Time.deltaTime);
|
||||||
}
|
}
|
||||||
else if (Input.GetAxis("Vertical")<0)
|
else if (Input.GetAxis("Vertical") < 0)
|
||||||
{
|
{
|
||||||
characterRigidBody.velocity = (-fowardVector * speed * boostFactor * Time.deltaTime);
|
characterRigidBody.velocity = (-fowardVector * speed * boostFactor * Time.deltaTime);
|
||||||
}
|
}
|
||||||
if (Input.GetAxis("Horizontal")<0)
|
if (Input.GetAxis("Horizontal") < 0)
|
||||||
{
|
{
|
||||||
characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime);
|
characterRigidBody.velocity = (Vector3.Cross(-transform.up, fowardVector) * speed * boostFactor * Time.deltaTime );
|
||||||
}
|
}
|
||||||
else if (Input.GetAxis("Horizontal") > 0)
|
else if (Input.GetAxis("Horizontal") > 0)
|
||||||
{
|
{
|
||||||
@ -35,31 +49,46 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FixedUpdate()
|
void OnTriggerEnter(Collider other)
|
||||||
{
|
|
||||||
SpeedBoostTimer(seconds);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnTriggerEnter (Collider other)
|
|
||||||
{
|
{
|
||||||
if (other.gameObject.tag == "SpeedBoost")
|
if (other.gameObject.tag == "SpeedBoost")
|
||||||
{
|
{
|
||||||
other.gameObject.SetActive (false);
|
other.gameObject.SetActive(false);
|
||||||
SpeedBoostTimerStart = true;
|
SpeedBoostTimerStart = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (other.gameObject.CompareTag("Slowmo"))
|
||||||
|
{
|
||||||
|
SlowmoTimerStart = true;
|
||||||
|
other.gameObject.SetActive(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SpeedBoostTimer(float seconds)
|
private void SpeedBoostTimer(float seconds)
|
||||||
{
|
{
|
||||||
if (SpeedBoostTimerStart)
|
if (SpeedBoostTimerStart)
|
||||||
{
|
{
|
||||||
boostFactor = 8f;
|
boostFactor = 8.0f;
|
||||||
initialTime = Time.realtimeSinceStartup + seconds;
|
boostDeadline = Time.realtimeSinceStartup + seconds;
|
||||||
SpeedBoostTimerStart = false;
|
SpeedBoostTimerStart = false;
|
||||||
}
|
}
|
||||||
if (Time.realtimeSinceStartup >= initialTime)
|
if (Time.realtimeSinceStartup >= boostDeadline)
|
||||||
{
|
{
|
||||||
boostFactor = 1f;
|
boostFactor = 1.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SlowmoTimer(float seconds)
|
||||||
|
{
|
||||||
|
if (SlowmoTimerStart)
|
||||||
|
{
|
||||||
|
TimeManager.SlowFactor = 0.2f;
|
||||||
|
slowmoDeadline = Time.realtimeSinceStartup + seconds;
|
||||||
|
SlowmoTimerStart = false;
|
||||||
|
}
|
||||||
|
if (Time.realtimeSinceStartup >= slowmoDeadline)
|
||||||
|
{
|
||||||
|
TimeManager.SlowFactor = 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
Assets/Scripts/TimeManager.cs
Normal file
18
Assets/Scripts/TimeManager.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public static class TimeManager
|
||||||
|
{
|
||||||
|
private static float slowFactor;
|
||||||
|
public static float SlowFactor
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return slowFactor;
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
slowFactor = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -7,7 +7,7 @@ public class ViewControl : MonoBehaviour
|
|||||||
// Speed at which the camera will catch up to the mouse pointer location
|
// Speed at which the camera will catch up to the mouse pointer location
|
||||||
public float mouseSensitivity = 100.0f;
|
public float mouseSensitivity = 100.0f;
|
||||||
public float clampAngle = 80.0f;
|
public float clampAngle = 80.0f;
|
||||||
|
|
||||||
private float rotY = 0.0f;
|
private float rotY = 0.0f;
|
||||||
// rotation around the up/y axis
|
// rotation around the up/y axis
|
||||||
private float rotX = 0.0f;
|
private float rotX = 0.0f;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user