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
0
Question by CallToAdventure · Feb 07, 2011 at 11:06 AM · transformrotateangle

Transform Rotate a certain angle (and back)

Hi everyone,

I am trying to rotate a game object with a certain degree (say -10) when a condition is met then rotate it back when that condition is off. I tried this:

 transform.Rotate(-10*Time.deltaTime, 0, 0);

But this will keep rotating the object over time; Maybe I should add an angle variable but I don't know how.

I'll keep looking though:)

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Myth · Feb 07, 2011 at 11:23 AM

you are right about the variable

the piece of code above will rotate on the x axis by 10 degrees per seccond

you could use

fromRotation = transform.rotation; toRotation = Quaternion.Euler(x,y,z);
transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
Comment
Add comment · 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
0

Answer by CallToAdventure · Feb 08, 2011 at 08:45 PM

i am 'answering' just to be able to add code formatting:

I am only a beginner in scripting so a lot to learn how to put things together. Naturally I missed a few things (not sure how to define the other variables in your example); This might be similar to another problem I have, maybe I will understand how transforming objects over time with variables like above (using time) or like in the next example: i am trying to rotate an object full 360 degrees without having to keep the button pressed; now I use:

var tumble = 360;

.... and in update function

if(Input.GetButton("Tumble"))

{ transform.Rotate(0, 0, tumble*Time.deltaTime); }

Funny thing is I have both answers only they work each for the other question :) the behavior of the second example should be in the first one and the other way around. Bare with me here and try not to laugh too hard :)

Comment
Add comment · 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

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

Calc 30° left and x units forward from local forward axis 1 Answer

Rotate an Object based on shorter angle 1 Answer

Transform.Rotate() stuck at 90 and 270 degrees 3 Answers

Rotate 90 over time on mouseDown 2 Answers

How can I rotate the transform by a specific angle at a certain speed? 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