- Home /
AddRelativeForce with a rigidbody2D ?
Hello,
Before unity 4.3 update, I was using AddRelativeForce to make my sprite go "forward" with this line of code :
`rigidbody.AddRelativeForce(Vector3.up * Time.deltaTime * SPEED);`
Is there an easy way to do the same with a rigidbody2D (without unsing sin/cos) ?
I'm also wondering this. It seems like the 2D physics is missing many things the 3D physics has. I hope they are going to be implemented soon...
Answer by robertbu · Dec 26, 2013 at 05:19 AM
In this particular case, you should be able to use
rigidbody2d.AddForce(transform.up * Time.deltaTime * SPEED);
'transform.up' is the relative up transformed into world space. Alternately you could do:
ridgidbody2d.AddForce(transform.TransformDirection(Vector3.up) * Time.deltaTime * SPEED);
Transform.TransformDirection() takes a local position and transforms it into world space. This is a more general solution that works for any local vector, where by the 'transform.up', 'transform.right', 'transform.down' only work for directions that are axes aligned.
Your answer
Follow this Question
Related Questions
rigidbody2d.addforce for is not working for the x axis 0 Answers
2D AddForce towards direction with CONSTANT FORCE whether the direction is far or near. 1 Answer
AddForce to mouse direction not working well horizontally. 1 Answer
About Rigidbody2D.AddForce's duration... 2 Answers
Rigidbody2D.velocity is not working. 0 Answers