Hello all. I’ve been having some problems with character movement in Unity 2D lately. I’ve used RigidBody.Velocity in the past to move from left to right, but the amount of problems it amount to were immense. For one, I couldn’t Add Force to the X axis, if, say, I wanted to send my character in the opposite direction, without disabling the Velocity change in Update. When hitting a slanted corner, instead of sliding against the box collider, the player would just teleport to the side. I’ve recently tried using RigidBody.MovePosition, but that doesn’t seem to allow me to use RigidBody.AddForce on the player at all. Does anyone have any suggestions?
if you want your character to change moving direction from right to left without loss in Velocity, you can always do this
//assuming velocity is across one axis
rb.velocity = rb.velocity*-1;
//or if velocity is across two axis
Vector2 newVel = rb.velocity;
newVel.x = newVel.x * -1;
rb.velocity = newVel;
on the other hand, MovePosition is going to set a final destination position so if you AddForce to a rigidbody that is being controlled by MovePosition, it will have to change it’s destination position. To avoid such situation, it is better to AddForce in the direction you want him to move and fidget with the velocity as per need.