So I am just starting a 1st person platformer and I want to be able to sprint and slow down (kinda like crouch but no ducking). Both of these work individually, but in this script:
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if(isGrounded && velocity.y < 0) {velocity.y = -2f;}
if (Input.GetButton("Sprint") && isGrounded)
{
speed = 36f;
} else
{
speed = 12f;
};
if (Input.GetButton("left control") && isGrounded)
{
speed = 6f;
} else
{
speed = 12f;
};
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * speed * Time.deltaTime);
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
};
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
Shifting doesn’t work - no speed increase occurs, but control does. It seems like the shift was being cancelled out. I did experiment with a bunch of stuff like GetKey, GetButtonDown, GetKeyDownetc. and nothing seems to be working. Any ideas?