- Home /
I need to swing the ship on 2D
Hello community.
I need to swing the ship when I push the buttons up and down. How I can do this?
I know that in 3D mode I can do it with those lines
public float tilt;
rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, rigidbody.velocity.x * -tilt);
There's a way to do the same action on 2D? Or I need to do an animation or something similar?
Thanks for the help.
Regards.
Does that logic not work? In 2D or 3D it should be rotating around the Z-axis, which you accomplish in the snippet.
But I need to call it in a different way because rigidbody.rotation can't be used on rigidbody2D and when I try to write rigidbody2D.rotation it doesn't Works.
Refer to the documentation for Rigidbody2D.rotation. In Rigidbody2D, rotation is just a float and not a Quaternion.
Answer by HarshadK · Dec 19, 2014 at 07:16 AM
Based on your sample code this will work in 2D:
public float tilt;
rigidbody2D.rotation = rigidbody2D.velocity.x * -tilt;
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
there is no 'animation' attached to the gameobject but a script is trying to access it 2 Answers
Light bulb moving HELP 1 Answer
I need help with adding my character controller to a Character model 2 Answers
how to have a configurable joint model match a 3Dmesh animation 1 Answer