Question by
SirLloydd · Jul 22, 2020 at 03:28 PM ·
fpscharacter movement1st personsprintsprinting
cant regualte the sprint speed of my character,I cant change my sprint speed!!!
So I´ve added an option to sprint to my PlayerMovement. when Im pressing left shift the usual speed is supposed to go to a certain amount. But somehow, eventhough my character gets faster, I cant regulate how fast. I have even gone ahead and made the sprint speed a much smaller amount than the normal speed. Still my character is faster when i sprint mode than if I just walk.
public float speed = 0f;
public float Sprintspeed = 13f;
public float Walkspeed = 10f;
public float gravity = -10f;
public float jumpHeight = 5f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
Vector3 velocity;
bool isGrounded;
void Update()
{
movement();
}
public void movement()
{
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (isGrounded && velocity.y < 0)
{
velocity.y = -2f;
}
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
Vector3 move = transform.right * x + transform.forward * z;
if (Input.GetKey(KeyCode.LeftShift) && Input.GetKey(Keycode.W))
{
speed = Sprintspeed;
}
else
{
speed = Walkspeed;
}
controller.Move(move * speed * Time.deltaTime);
if (Input.GetButton("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}
as said before, I have changed the speed to extreme amounts but the sprintspeed is still the same. Would be very thankful if someone explain this to me!
Comment