- Home /
Can't move player with rigidbody.velocity
Hi all. I just started working on a 2D beat'em up. I started doing it with the 2D settings, but soon discovered that I would have to switch to 3D in order to be able to move the characters in depth too, like in the classic beat'em ups, not just from right to left. All the graphics are going to be 2D anyway.
So I'm struggling now to make the player move. I've set up a plane object, and the character object has a rigidbody and a box collider. So, to make the character move, I'm doing something like this:
xSpeed = horizontalMove * speedIncrease;
rigidbody.velocity = new Vector3 (xSpeed, 0, 0);
What am I doing wrong?
Thanks in advance
Answer by Nanobrain · Mar 02, 2014 at 06:43 PM
Note in the documentation for rigidbody.velocity:
In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour.
Therefore, use rigidbody.AddForce(Vector3, Forcemode)
rigidbody.AddForce(new Vector3(xSpeed, 0, 0), ForceMode.VelocityChange);
There are 4 different Force Modes that create different results when adding force. Read the documentation about Force Mode here. I would try each of them out to choose which mode has the best effect for your current situation.
Thanks @Nanobrain. I actually read the documentation, but I guess I was making the error of trying to move the rigidbody as they are moved in 2D.
Your answer
Follow this Question
Related Questions
Npc Movement 0 Answers
Movement Script Only Works in One Scene 2 Answers
Constrain character to series of intersecting paths? 1 Answer
Change player movement 0 Answers
Constrain rigidbody movement to spline at high speeds / sharp curves 3 Answers