- Home /
How to give smooth constant move to a player object
Hey everyone i am making a endless runner game. I use the code below for moving player constantly forward. Code works okey but sometimes player object having some shakes. It is keep going forward but looks like a move with lag(it is look like 1cm teleports to forward and back , but keep moving straight). So i need a smoother movement. I have tried some other movement pyhsics but they did not work well for me. So basically i need to move character at z axis constantly. Here is the code i use
public RigidBody rb;
forwardSpeed =5 ;
private void FixedUpdate()
{
Vector3 forwardMove = transform.forward * forwardSpeed * Time.fixedDeltaTime;
rb.MovePosition(rb.position + forwardMove);
}
Answer by sebkociedwards · Feb 27 at 05:51 PM
From this I am assuming that you're camera has the same script attached or same code to move with the player. If this is the case it might be that the code for the camera movement is in a Update or FixedUpdate function. If it is try changing it to LateUpdate which will mean every frame the player will render first which should stop the stuttering. It would look something like this for the camera script: private void LateUpdate(){ transform.Translate(Vector3.forward speed Time.deltaTime); }
I was using CineMachineBraing plugin for camera move. After i read your comment i made a simple camera follow script, now the shaking problem is permament, so i found the problem. I am going to solve it. Thx for help!
Your answer

Follow this Question
Related Questions
How can I enable my capsule to move; object 'target' not recognized. 0 Answers
Move Object to location of Trigger? 1 Answer
Stop object with mouse 0 Answers
Why is the Enemy's Sprite Flipping When it Sees the Player?? 0 Answers
When I move the joystick and then release it, the input is not 0. 2 Answers