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:
void FixedUpdate()
{
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
}
}