- Home /
Player movement not working with unity 5
Hello. Just installed Unity 5, and everything seems to be working with my project except one big thing, which is the movement. THe game is an old school point and click adventure game, so the movement is basically just a mouse click. This is the code to get my characters velocity:
GetComponent<Rigidbody2D>().velocity = positionDirection.normalized;
//positionDirection is the target for movement
If I take off "Kinematic" in my Rigidbody2D. The character does go towards the target, so there is something that works... Is there something wrong with this code now? Any changes to the way this works?
Answer by Stealthygolem · Mar 04, 2015 at 02:20 PM
I reworked my code to rather move with an AddRelativeForce
with the same Rigidbody2D
component. Applying this code was the most important:
GetComponent<Rigidbody2D>().AddRelativeForce(positionDirection.normalized * speed);
And I had to fix and add variables to work with correct rotation. Extra code explaining this would require a lot more of the scripting to examplify it understandably.
Still, if anyone could answer the original question, why my character originally didn't want to move, I would like that! Thanks