Jump to content
  • Advertisement
Sign in to follow this  
LiziPizi

How do I rotate an object back and forth?

This topic is 474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want my object to rotate between two angles in relation to speed and it doesn't need to be a smooth rotation, how can I achieve that? 

Thank you in advance.

 

Share this post


Link to post
Share on other sites
Advertisement
Like a speedometer needle?

When the speed changes, do the following:
 
float normalizedSpeed = actualSpeed / kMaximumSpeedForSpeedometer;

if (normalizedSpeed < 0.0f) // You can also use Mathf.clamp if you want.
   normalizedSpeed = 0.0f;
else if (normalizedSpeed > 1.0f)
   normalizedSpeed = 1.0f;

float angleForSpeedometer = normalizedSpeed * (maximumAngle - minimumAngle) + minimumAngle;

// set the speedometer needle's transform rotation using this angle.
// see: https://docs.unity3d.com/ScriptReference/Transform-rotation.html
// or: https://docs.unity3d.com/ScriptReference/Transform-eulerAngles.html
maximumAngle is a rotation angle that you specify for the top-speed of the needle. minimumAngle is the same thing but for the zero-speed angle. Edited by Nypyren

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!