This commit is contained in:
karakune 2016-06-26 11:00:34 -04:00
commit 807e28a401
3 changed files with 72 additions and 25 deletions

View File

@ -1,33 +1,47 @@
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public class PlayerMovement : MonoBehaviour
{
public float speed = 0f;
public float turn = 0f;
public Rigidbody characterRigidBody;
// Boost
public float boostFactor = 1f;
public float seconds;
float initialTime;
float boostDeadline;
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
void Update () {
// Update is called once per frame
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);
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);
}
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)
{
@ -35,31 +49,46 @@ public class PlayerMovement : MonoBehaviour {
}
}
void FixedUpdate()
{
SpeedBoostTimer(seconds);
}
void OnTriggerEnter (Collider other)
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "SpeedBoost")
{
other.gameObject.SetActive (false);
other.gameObject.SetActive(false);
SpeedBoostTimerStart = true;
}
if (other.gameObject.CompareTag("Slowmo"))
{
SlowmoTimerStart = true;
other.gameObject.SetActive(false);
}
}
private void SpeedBoostTimer(float seconds)
{
if (SpeedBoostTimerStart)
{
boostFactor = 8f;
initialTime = Time.realtimeSinceStartup + seconds;
boostFactor = 8.0f;
boostDeadline = Time.realtimeSinceStartup + seconds;
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;
}
}
}

View 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;
}
}
}

View File

@ -7,7 +7,7 @@ public class ViewControl : MonoBehaviour
// Speed at which the camera will catch up to the mouse pointer location
public float mouseSensitivity = 100.0f;
public float clampAngle = 80.0f;
private float rotY = 0.0f;
// rotation around the up/y axis
private float rotX = 0.0f;