1
0
Fork 0

Player brake time

This commit is contained in:
Piegames 2018-04-23 21:30:31 +02:00
parent c2bf1bee8c
commit bfa790adb6
3 changed files with 30 additions and 4 deletions

View file

@ -14,11 +14,16 @@ public class PlayerMovement : MonoBehaviour {
public float drift = 1f;
[SerializeField]
public float brake = 2f;
[SerializeField]
public float maxBrakeTime = 30f;
// The time of the acceleration/deceleration sounds in seconds
public double accelerationTime;
public double decelerationTime;
public float brakeTime;
public float lastFrame;
public enum SpeedState
{
SLOW, FASTER, FAST, SLOWER
@ -34,6 +39,8 @@ public class PlayerMovement : MonoBehaviour {
rb = GetComponent<Rigidbody2D>();
messagePosted = false;
state = SpeedState.SLOW;
brakeTime = 0;
lastFrame = Time.time;
}
void Update() {
@ -56,7 +63,12 @@ public class PlayerMovement : MonoBehaviour {
float speed = speedVec.magnitude;
bool braking = Input.GetAxis("Vertical") < 0;
if (brakeTime > maxBrakeTime) {
brakeTime = maxBrakeTime;
braking = false;
}
if (braking) {
brakeTime += Time.time - lastFrame;
switch (state) {
case SpeedState.FASTER:
if (Time.time - changeTime > accelerationTime)
@ -138,5 +150,11 @@ public class PlayerMovement : MonoBehaviour {
//Debug.Log(transform.localRotation.eulerAngles);
//Debug.Log(transform.localRotation * Vector3.up);
//Debug.Log(curspeed);
lastFrame = Time.time;
}
/// <returns>The time in seconds the player was braking</returns>
public float GetBrakeTime() {
return brakeTime;
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 344607e4adabd53428aa359d92c5daf0
guid: 9ec323b9157704d00a3409f8ea6e46b2
folderAsset: yes
DefaultImporter:
externalObjects: {}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: df6e7833427b5497b92308fb6f54e552
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: