- Home /
What is equivalent to Transform.up when moving and rotating the RigidBody2D component instead?
I am developing a 2D game.
I used to move and rotate my GameObject along a Bezier curve by altering transform
properties until I did a little research and found out that using RigidBody2D
methods is a lot better way to go with and offers more performance.
However, now I have a problem. I used to set transform.up
to the first derivative of Bezier to rotate the object so that it always follows the curve by the right angle.
I can't find a way to properly rotate my GameObject. How can I achieve the same effect without modifying transform.up
? What is equivalent to transform.up
when using RigidBody2D
?
Thank you!
Answer by HristijanWildChild · Sep 01, 2017 at 02:31 PM
If anyone ever visits this question and has the same problem, this is the code to do it:
// Move the character
// transform.position = bezier;
rigidBody.MovePosition(bezier);
// Rotate the character so that the top of the sprite always lies on the curve
// transform.up = firstDerivativeBezier;
float anglesToRotate = Mathf.Atan2(firstDerivativeBezier.y, firstDerivativeBezier.x) * Mathf.Rad2Deg - 90f;
rigidBody.MoveRotation(anglesToRotate);
And the answer lies here:
https://math.stackexchange.com/questions/477165/find-angle-at-point-on-bezier-curve https://docs.unity3d.com/ScriptReference/Mathf.Atan2.html
Your answer
![](https://koobas.hobune.stream/wayback/20220612133743im_/https://answers.unity.com/themes/thub/images/avi.jpg)