Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Ben 4 · Apr 06, 2010 at 04:09 PM · transformrotatetimeangledegrees

Rotate 90 over time on mouseDown

This is in the main character controller script and is controlled by a ray collision on an update function:

if (Input.GetMouseButtonDown(0)){
    miniNode.GetComponent(rotationHandlerLeft).rotateLeftSmall();
    }

And this is what I have for moving the rotations right now which works great but Id love for there to be some smooth Animation over time that locks at 90 increments, these are in a seperate script that has no update function at the moment :

function rotateLeftSmall () {
    transform.Rotate(Vector3.up*-90); // Rotate to the left
    print("Left Rotation");
    }

I think this will work but im having trouble with where the updates go I think.

function rotateLeftSmall () {
    transform.Rotate(Vector3.up * Time.deltaTime * -90)
    }

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
4
Best Answer

Answer by Eric5h5 · Apr 06, 2010 at 04:43 PM

Use a coroutine:

private var rotating = false;

function RotateObject (thisTransform : Transform, degrees : Vector3, seconds : float) { if (rotating) return; rotating = true;

 var startRotation = thisTransform.rotation;
 var endRotation = thisTransform.rotation * Quaternion.Euler(degrees);
 var t = 0.0;
 var rate = 1.0/seconds;
 while (t < 1.0) {
     t += Time.deltaTime * rate;
     thisTransform.rotation = Quaternion.Slerp(startRotation, endRotation, t);
     yield;
 }

 rotating = false;

}

Which is called like this:

RotateObject(transform, Vector3.up*-90, .5);
Comment
Add comment · Show 4 · 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 Ben 4 · Apr 06, 2010 at 08:15 PM 0
Share

Is there anyway to failsafe this, so that It must play out the full duration before the user can click to invoke the function to run again, thus throwing off the 90 increments?

avatar image Eric5h5 · Apr 06, 2010 at 08:33 PM 0
Share

@Ben: Yes, I edited the code so it can't be interrupted.

avatar image Mentalist4006 · Oct 13, 2010 at 12:40 AM 0
Share

I did what you said, I made this script and is called from another script's "Update" function. The error box says "Update() can not take parameters." Is there something wrong in putting this together?

avatar image Danny S. · Mar 31, 2011 at 04:46 PM 0
Share

Wow, this provides the same functionality as about 80 lines of code I wrote. +1 to you sir.

avatar image
1

Answer by e-bonneville · Apr 06, 2010 at 04:31 PM

Well, what you want to do is something along these lines:

function Update () {
    if (Input.GetMouseButtonDown(0)){
         transform.Rotate(Vector3.up * Time.deltaTime * -90); 
    }
}

This will rotate your object to the left when you press mouse 0. Replace

if (Input.GetMouseButtonDown(0)){
    miniNode.GetComponent(rotationHandlerLeft).rotateLeftSmall(); 
    }

with

if (Input.GetMouseButtonDown(0)){
    transform.Rotate(Vector3.up * Time.deltaTime * -90); 
}

in your Update function.

Comment
Add comment · Show 2 · 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 Eric5h5 · Apr 06, 2010 at 04:55 PM 0
Share

That won't work, because Get$$anonymous$$ouseButtonDown is called only once, so all it would do is rotate a fraction of the full 90 degrees. Also Ben wanted it to rotate smoothly the full 90 degrees on mouse down, so this is not something you can easily do in Update at all.

avatar image e-bonneville · Apr 06, 2010 at 05:24 PM 0
Share

Oh, you're right. I lack knowledge of the logic of coding, and although I know the API, I trip up a lot like that. Thanks for pointing that out.

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

Rotate 90 degrees over time with Parabolic Easing. 1 Answer

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

Transform Rotate a certain angle (and back) 2 Answers

Rotate object in a set amount of time 1 Answer

Gradually Rotate Character 90 Degrees 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