- Home /
RigidBody.MovePosition seems jerky in movement
Hey everyone,
So my goal is to make my own FPS controller so I have more control over exactly how I want the feel of movement to be.
The FPS controller must be influenced by physics, and also in a more realistic way. This means that if you walk along and bump into an object heavier than the FPS controller, that object must be hard to push aside, etc.
Now here's the problem.
I've found that using a rigid body with the RigidBody.MovePosition method gives me exactly what I want. I can move around in a fast-paced manner (not having to deal with slower controls by using AddForce etc, since this would also cause acceleration and feel not quite as accurate to the player), and bumping into other physical objects cause the player to slow down when those other objects are heavy. This is all perfect.
The only problem that I'm having is that the movement feels very jerky and not smooth at all. I read around a bit on found out this guy had the same problem: Official Unity3D Forum Thread
The problem is, the answer provided by AngryAnt of moving the movement code to "Update" instead of "FixedUpdate" for smooth movement simply doesn't seem to work. The movement is still as jerky as it was before. What fixes this is by upping the Fixed time step interval of the physics engine, but I feel this is no good solution at all to a simple character movement problem.
My Question
My question then is, how do I get to have full control over my rigid body to provide smooth and very reactive controls, whilst also being affect by physics realistically? MovePosition does almost all of this, except the smooth movement, which is a bummer. Am I doing something wrong?
Setting the rigidbody to kinematic isn't really that awesome, because it can simply push anything out of the way no matter what mass they have, etc.
My Code
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.W))
{
rigidbody.MovePosition(new Vector3(rigidbody.position.x,
rigidbody.position.y,
rigidbody.position.z + forwardMovementSpeed * Time.deltaTime));
}
if (Input.GetKey(KeyCode.S))
{
rigidbody.MovePosition(new Vector3(rigidbody.position.x,
rigidbody.position.y,
rigidbody.position.z - backwardMovementSpeed * Time.deltaTime));
}
if (Input.GetKey(KeyCode.A))
{
rigidbody.MovePosition(new Vector3(rigidbody.position.x - sidewaysMovementSpeed * Time.deltaTime,
rigidbody.position.y,
rigidbody.position.z));
}
if (Input.GetKey(KeyCode.D))
{
rigidbody.MovePosition(new Vector3(rigidbody.position.x + sidewaysMovementSpeed * Time.deltaTime,
rigidbody.position.y,
rigidbody.position.z));
}
if (Input.GetKey(KeyCode.Space))
{
}
}
Your answer
Follow this Question
Related Questions
RigidBody immediately stops after AddForce 1 Answer
Interpolate problem? Jump isn't smooth... 1 Answer
Force to Velocity scaling? 2 Answers
Sometimes the ball isn't moving 0 Answers