I have an object(shark) moving up and down and when it's at the bottom, it rotates 180 degrees. But sometimes it turns over it's belly and sometimes over it's back. I want to have it so that it always rotates on it's belly and not on it's back. How can I fix this?
Also the starting rotation is -90 degrees X axis. Here's the code:
transform.Translate(Vector3.forward * speed * Time.deltaTime);
targetAnglesUp = transform.eulerAngles + 180 * Vector3.right; // what the new angles should be
targetAnglesDown = transform.eulerAngles + 180 * Vector3.right; // what the new angles should be
if (transform.position.y >= 150)
transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAnglesUp, smooth * Time.deltaTime); // lerp to new angles
if (transform.position.y <= 50)
transform.eulerAngles = Vector3.Lerp(transform.eulerAngles, targetAnglesDown, smooth * Time.deltaTime); // lerp to new angles
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
3 People are following this question.
Aligning a hovercraft to two axis of a transform
How to Make animation Playable?
Rotating a Sprite to face mouse / target?
Rotating a bone upwards relative to camera.
Restricting rotation on an axis