Fully functional and satisfactory acc/decc in movement (although a little slippery, might require more tweakign later on)

This commit is contained in:
Gregory Campbell
2020-01-04 16:15:15 -05:00
parent 386b51589e
commit 996e1e3b20
+14 -14
View File
@@ -12,7 +12,6 @@ public class PlayerController : MonoBehaviour
CharacterController characterController; CharacterController characterController;
CapsuleCollider capsule; CapsuleCollider capsule;
public float speed;
public float maxSpeed; public float maxSpeed;
public float acceleration; public float acceleration;
public float friction; public float friction;
@@ -69,11 +68,11 @@ public class PlayerController : MonoBehaviour
moveDirection = transform.TransformDirection(moveDirection); moveDirection = transform.TransformDirection(moveDirection);
moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f); moveDirection = Vector3.ClampMagnitude(moveDirection, 1.0f);
if (jump > 2) if (jump >= 2)
{ {
if(maxSpeed > maxSpeedStore/3) if(maxSpeed > maxSpeedStore/1.75f)
{ {
maxSpeed -= acceleration*3; maxSpeed -= acceleration;
} }
} }
@@ -84,20 +83,22 @@ public class PlayerController : MonoBehaviour
jump = 0; jump = 0;
moveDirection.y = 0.0f; moveDirection.y = 0.0f;
if(maxSpeed > maxSpeedStore)
{
maxSpeed -= acceleration/10;
}
if(maxSpeed < maxSpeedStore && !Input.GetKey(KeyCode.LeftShift) && !Input.GetKey(KeyCode.LeftControl))
{
maxSpeed += acceleration;
}
if(Input.GetKey(KeyCode.LeftShift)) if(Input.GetKey(KeyCode.LeftShift))
{ {
if(maxSpeed > maxSpeedStore/2) if(maxSpeed > maxSpeedStore/2)
{ {
maxSpeed -= acceleration; maxSpeed -= acceleration;
} }
}
if(Input.GetKeyUp(KeyCode.LeftShift) || Input.GetKeyUp(KeyCode.LeftControl))
{
while(maxSpeed < maxSpeedStore)
{
maxSpeed += acceleration;
}
} }
if(Input.GetKey(KeyCode.LeftControl)) if(Input.GetKey(KeyCode.LeftControl))
@@ -118,7 +119,7 @@ public class PlayerController : MonoBehaviour
if(maxSpeed < maxSpeedStore*2) if(maxSpeed < maxSpeedStore*2)
{ {
maxSpeed += acceleration; maxSpeed += acceleration*2;
} }
} else { } else {
@@ -132,7 +133,6 @@ public class PlayerController : MonoBehaviour
} else { } else {
//maxSpeed = maxSpeedStore;
characterController.height = controllerHeight; characterController.height = controllerHeight;
capsule.height = capsuleHeight; capsule.height = capsuleHeight;
transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z); transform.localScale = new Vector3(transform.localScale.x, transformHeight, transform.localScale.z);