- Home /
Change rotation until it's at 0,0,0
I'm really new to programming in general and I would like to know how I can change the rotation of an object so that it tries to stay upright. Not instantly, but pretty quickly.
I'm pretty sure it has something to do with this code:
if (transform.eulerAngles !== new Vector3(0f, 0f, 0f)) {etc}
Sorry.
Welcome to program$$anonymous$$g :) You're definitely in for a huge learning curve, but if you're like me then you will enjoy the challenge.
Just a few tips with your statement above:
!== should be !=
Vector3(0f, 0f, 0f) would be the zero vector. Straight up is Vector3(0f, 1f, 0f) or just use Vector3.up for short.
Answer by greatwhiteshark17283 · Feb 11, 2014 at 12:43 AM
Try using Quaternion.identity. See this documentation.
I'm not quite sure what your application is, but the following code will rotate an object towards straight up a little bit every frame. It is not physically realistic, but it will get the job done.
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.identity, 0.1f);
Just a wild guess, but is this a rigidBody?
Take a look at the CharacterController component. It is designed to move player-characters around. It allows for simplified physics while keeping the character upright.
If you need the tipping motion, you could use a ConfigurableJoint to make a RigidBody spring back upright. You can do it all in the editor without having to program anything.
Your answer
Follow this Question
Related Questions
Rotating Y towards X/Z 1 Answer
How to recognise every vertices's position in model and keep track of them in scene window? 1 Answer
Can't move instantiated prefab 2 Answers
aiming up and down 0 Answers