# Moving a rigidbody across a 2D plane

I'm creating a sports game, and I'm having trouble getting my players controlling correctly. At the moment, I have them setup as simple box colliders with a kinematic rigidbody. I am then using the Trigger methods to check for collisions with other players / the ball. My players do need to be effected by gravity or any other forces, so using kinematic rigidbodies seems a better option than using a CC or a physics based RigidBody.

I am using the following code to 'control' my players when they are activated:

``````void Update() {

if(_position != Vector3.zero)
{
_player.transform.rotation = Quaternion.Slerp(_player.transform.rotation, Quaternion.LookRotation(_position), Time.deltaTime * 10);
_player.rigidbody.MovePosition(_player.rigidbody.position + (_position*_player.playerSpeed)*Time.deltaTime);
}
}

void FixedUpdate() {
_position = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
_position = _position.normalized;
}

``````

So, in my Update I am setting the _position Vector to the new position, then moving the rigidbody in the FixedUpdate method (apparently this is faster than doing the calculations in the FixedUpdate?)

The problem is that my player seems to 'snap' to a direction when you let go of the inputs. This is only really noticeable when moving diagonally, but I want to make my player movement as smooth as possible. I'd also like to add a little bit of friction, as at the moment they stop dead when you release the input keys.

Firstly, is my kinematic rigidbody setup the right way to go? If so, can anyone suggest a way in which I could make the movement a little smoother and more realistic?

Many thanks!

You might find this example helpful: http://vonlehecreative.wordpress.com/2010/01/28/unity-resource-xycontroller/

It shows how to move a kinematic rigidbody in the x/y plane. Switching it to the x/z plane and adding some rotation shouldn't be too difficult.

One comment on your code: you shouldn't need to use both Update and FixedUpdate. When working with rigidbodies, the docs recommend using FixedUpdate.