- Home /
Question by
StudentofMany · Nov 04, 2020 at 04:42 AM ·
c#game development
Faster movement speed when FPS is lower?
//Movement calculations
float xMove = Input.GetAxis("Horizontal");
float zMove = Input.GetAxis("Vertical");
Vector3 horMovement = xMove * transform.right;
Vector3 vertMovement = zMove * transform.forward;
velocity = (horMovement + vertMovement) * movementSpeed * Time.deltaTime;
//Execute Movement
rb.MovePosition(rb.position + velocity);
Comment
Answer by rh_galaxy · Nov 04, 2020 at 01:11 PM
Consider doing the calculations in FixedUpdate, but you should read about it and why and how.
Also your velocity var isn't the velocity but the distance to move on one frame. And you will move faster diagonally if you don't do:
(horMovement + vertMovement).Normalize()
And it's no good to move position yourself when having a rigidbody, you should just set the velocity and let it be moved by the physics engine.
rb.velocity = (horMovement + vertMovement).Normalize() * movementSpeed;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Global custom timer 1 Answer
I want to increase the health bar when I press a button. 2 Answers
Object rotation snaps back to 0° 1 Answer