Player brake time
This commit is contained in:
parent
c2bf1bee8c
commit
bfa790adb6
3 changed files with 30 additions and 4 deletions
|
@ -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)
|
||||
|
@ -135,8 +147,14 @@ public class PlayerMovement : MonoBehaviour {
|
|||
Debug.DrawLine(transform.position, transform.position + speedVec, Color.magenta, 0.01f, false);
|
||||
Debug.DrawLine(transform.position, transform.position + transform.localRotation * Vector3.up, Color.yellow, 0.01f, false);
|
||||
|
||||
//Debug.Log(transform.localRotation.eulerAngles);
|
||||
//Debug.Log(transform.localRotation * Vector3.up);
|
||||
//Debug.Log(curspeed);
|
||||
//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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 344607e4adabd53428aa359d92c5daf0
|
||||
guid: 9ec323b9157704d00a3409f8ea6e46b2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
8
Assets/graphics/textures/tmp.meta
Normal file
8
Assets/graphics/textures/tmp.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: df6e7833427b5497b92308fb6f54e552
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Reference in a new issue