MovePosition on a single axis, retain velocity on the other

Hey all,

I’m using MovePosition to move a crate with the player when pushing/pulling. This works great.

The issue is that when applying the new X position, the current Y position is also applied, causing it to create janky y axis behaviour.

pushableRigidbody.MovePosition (new Vector2( pushableTargetX, pushableRigidbody.position.y ) );

Is there any way to only use MovePosition on the x axis only?

By passing in the existing body.y position, this won’t change the Y position at all. MovePosition simply calculates the velocity required to move the Rigidbody2D in a single physics update, it doesn’t directly alter position.

Also know that if you’re using Rigidbody2D interpolation then the Rigidbody2D position will be different than the Transform position (transform is interpolated each frame).

Presumably you’re not calling this each frame because it would be pointless as MovePosition only works during the physics update (FixedUpdate).

You might want to try dumping the Rigidbody2D position and the Transform position prior to calling MovePosition to check what you’re asking it to do.