Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Qwerty · Feb 02, 2011 at 11:19 PM · rotationrotateoncedegrees

Rotation: rotate by a defined angle

Hi everyone,

I have been trying to get a smooth and visually pleasing way of have an object (plane in my case) tilt by about 50 degrees on a command.

So far I have tried:

Case 1:eulerAngle rotations --> Works pretty well but way to jerky (happening in one frame) if i added the Time.deltaTime it only did what the amount of degrees for 1 second.

Case 2:Quaternions --> Never got this to work well... continued to rotate when ever the button was pressed (could not get it to stop at 50 degrees).

Case 3: calling another function --> this by far works the best, however, if the key is lifted "GetButtonUp" before the angle movement for "GetButtonDown" is finished (ie: it only had time to go 20 degrees) the plane overshoots its level position.

In theory I feel like this should be really simple! heres a picture to make it clear (i eventually want to connect it to my GUI joystick, but for now I'm happy to get it working on a button down for keyboard)

for anyone looking for a similar solution:

--Heres the NEW code-- that I am using based on the answer suggestion for my situation

(there are still some issues with how I return to the flat, I will post the updated script when I work it out. Thanks for the help!**

var currentx = transform.eulerAngles.x; var currenty = transform.eulerAngles.y;

if(Input.GetAxis("a")){

 fromRotation = transform.rotation; toRotation = Quaternion.Euler(currentx,currenty,110); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);

}else{isTurning = 1;}

if(Input.GetAxis("d")){

 fromRotation = transform.rotation; toRotation = Quaternion.Euler(currentx,currenty,-110); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);

}else{isTurning = 1;}

//isTurning 0=yes 1=no (so flatten out) if(isTurning == 1){ fromRotation = transform.rotation; toRotation = Quaternion.Euler(currentx,currenty,0); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed); isTurning = 0; }

Thanks for your help

[1]: demo

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Myth · Feb 02, 2011 at 11:30 PM

a little bitta code taken straight outta something I'm putting together that may be able to help

fromRotation = transform.rotation; toRotation = Quaternion.Euler(aa,bb,cc); transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);

the " Lerp " part being the important bit

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Qwerty · Feb 03, 2011 at 01:05 AM 0
Share

YES!! Thank you! this seems to work perfectly, its pretty much exactly what I was looking for.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Problem with "if or" statement. 1 Answer

How can I rotate an object with certain degrees? 2 Answers

Rotate object in 45 degree steps 1 Answer

What is the most efficient way to rotate an object? 3 Answers

90 degrees isnt? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges