Question by
SollerEtFortis · Jan 29, 2020 at 02:19 AM ·
movementfps controllersprinting
I am trying to make my FPS character sprint. However, instead of sprinting he "teleports", instead of transforming position gradually. Here is a piece of code that deals with movement and sprinting.
void Update()
{
isGrounded = Physics.CheckSphere(groundCheck.position,
groundDistance, groundMask);
if (isGrounded && velocity.y <= 0)
{
velocity.y = -1.0f ;
}
float deltaX = Input.GetAxisRaw("Horizontal") * movementSpeed;
float deltaZ = Input.GetAxisRaw("Vertical") * movementSpeed;
Vector3 movement = transform.right * deltaX + transform.forward
* deltaZ;
_characterController.Move(movement * movementSpeed *
Time.deltaTime);
if (Input.GetKeyDown(KeyCode.LeftShift) && isGrounded)
{
movementSpeed = sprint;
}
else
{
movementSpeed = 10.0f;
}
if (Input.GetButtonDown("Jump") && isGrounded)
{
velocity.y = Mathf.Sqrt(jumpForce * -2.0f * gravity);
}
velocity.y += gravity * Time.deltaTime;
_characterController.Move(velocity);
}
Comment
Your answer
Follow this Question
Related Questions
Character sometimes moves faster when I jump and start moving at the same time 1 Answer
FPSController - Moves only in "Scene", not "Game" 0 Answers
When I click a key I wantthe object to move, but instead it does nothing 0 Answers
Have an issue with looking and moving Unity3D 1 Answer
The Movement Values gets different with higher fps ?? 2 Answers