- Home /
rigidbody.AddForce(transform.forward * 5000)
I am making a simple first person game. I created a simple move script that i would build upon. I am using the MouseLook script from the character controller package. I am using rigidbody.AddForce to move my character around. I use this code to move my character forward: rigidbody.AddForce(transform.forward * 5000). It works fine but the only down side is if I look up and call that code it enables me to fly. I don't want that to happen. Is there a way to restrict the forward to only the y axis. I just want it to move forward in the y direction my character faces. Is there a easy way to fix this or use a different way to do this instead of rigidbody.AddForce.
i mean "fly" as shoots my player in the air because the forward is looking up and it goes it that direction
Answer by d2 · Mar 05, 2015 at 10:00 PM
try this:
rb.AddForce(new Vector3(transform.forward.x, 0 , transform.forward.z) * 5000);
Your answer
Follow this Question
Related Questions
Trying to make a Projectile Rotate and Move Forward.. 1 Answer
How to make an object without Rigidbody move at the same speed as an object with Rigidbody? 1 Answer
Moving relative to camera direction at constant speed (Velocity problem) 0 Answers
look at movedirection 1 Answer
How to move Character with Addforce? 1 Answer