- Home /
How do I add force based on rotation status of a sprite?
I'm trying to have my sprite move in the direction that it is pointed (via rotation). I can do it with transform.position but I want the effect of AddForce. I'm getting an error saying that I can't apply an * to a Vector3, an error saying I can't convert an object to Vector2, and an error saying there are some invalid arguments. I'm pretty new to Unity and am still figuring this environment out.
Answer by Mightymcc · Jul 13, 2015 at 12:23 AM
Nevermind, I figured it out. I had the code set up for the command to be transform.position with the code:
Vector3 pos = transform.position; Vector3 velocity = new Vector3(0, Input.GetAxis("Vertical") speed Time.deltaTime, 0); pos += rot velocity; rb2d.AddForce(Vector3.forward pos);
All I needed to do was change "Vector3 pos = transform.position;" to "Vector3 pos = Vector3.forward" and then change the last line to "rb2d.AddForce(pos);"
Your answer
Follow this Question
Related Questions
CAR ROTATING HELP 2 Answers
Look rotation viewing is zero warning 0 Answers
How can I turn the direction of bicycle in Unity? 3 Answers
How to get inspector rotation values ? 2 Answers
Instantiating bullet and moving forward with rigidbody 0 Answers