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
3
Question by dot · Oct 05, 2010 at 03:53 AM · rotationrotatearound

easing a rotation of ROTATE AROUND

I asked about easing a transform.Rotate function on the other thread http://answers.unity3d.com/questions/22252/how-to-ease-a-rotation

and I got a good "easing" code:

function Update () { if ( Input.GetMouseButtonDown(0)) RotateObject(transform.rotation,Quaternion.Euler(transform.rotation.eulerAngles + Vector3.forward * 90),2.0); }

function RotateObject(startRot : Quaternion, endRot : Quaternion, rotateTime : float) { var i = 0.0; var rate = 1.0/rotateTime; while (i < 1.0) { i += Time.deltaTime * rate; transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0.0, 1.0, i)); yield; } }

but as I went along with the project, I realized,I needed, in fact, an alternative for

transform.RotateAround not for transform.Rotate

and I don't think I understand that code enough, in order to make the rotation rotate around a given point in the space.

Do you think you do?

thank you in advance.

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

Answer by skovacs1 · Oct 05, 2010 at 05:45 PM

The reason that code works is because you are lerping. The reason you can lerp is that you are rotating in place. RotateAround also changes position so it doesn't quite work the same. There are two simple solutions.

Determine how much of our rotation to perform each time:

function RotateObject(point : Vector3, axis : Vector3,
                      rotateAmount : float, rotateTime : float) {
    var step : float = 0.0; //non-smoothed
    var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by
    var smoothStep : float = 0.0; //smooth step this time
    var lastStep : float = 0.0; //smooth step last time
    while(step < 1.0) { // until we're done
        step += Time.deltaTime * rate; //increase the step
        smoothStep = Mathf.SmoothStep(0.0, 1.0, step); //get the smooth step
        transform.RotateAround(point, axis, 
                               rotateAmount * (smoothStep - lastStep));
        lastStep = smoothStep; //store the smooth step
        yield;
    }
    //finish any left-over
    if(step > 1.0) transform.RotateAround(point, axis,
                                          rotateAmount * (1.0 - lastStep));
}

Slerp the position and rotation separately:

function RotateObject(point : Vector3, axis : Vector3, rotateAmount : float, rotateTime : float) { var rotation = Quaternion.AngleAxis(rotateAmount, axis);

 var startPos : Vector3 = transform.position - point;
 var endPos : Vector3 = rotation * startPos; 
 var startRot : Quaternion = transform.rotation;

 var step : float = 0.0; //non-smoothed
 var smoothStep : float = 0.0; //smoothed
 var rate : float = 1.0/rotateTime; //amount to increase non-smooth step by
 while(step &lt; 1.0) { // until we're done
     step += Time.deltaTime * rate; //increase the step
     smoothStep = Mathf.SmoothStep(0.0, 1.0, step);
     transform.position = point + Vector3.Slerp(startPos, endPos, smoothStep);
     transform.rotation = startRot * Quaternion.Slerp(Quaternion.identity,
                                                      rotation, smoothStep);
     yield;
 }
 //finish any left-over
 if(step &gt; 1.0) {
     transform.position = point + endPos;
     transform.rotation = startRot * rotation;
 }

}

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 dot · Oct 05, 2010 at 08:27 PM 0
Share

Thank you man! You're great!

avatar image dot · Oct 05, 2010 at 09:25 PM 1
Share

hmm on a side note, when I try to do something like this:

var sliceCubes:Transform[];

 if(Input.Get$$anonymous$$ouseButtonDown(0))
     for(var cube : Transform in sliceCubes) cube.RotateObject(centralCube.position, axisOfARotation, rotationAmount, howLongRotation);

it says RotateObject is not a member of UnityEngine.Transform

How to get rid of that problem?

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

1 Person is following this question.

avatar image

Related Questions

How to rotate an object around a fixed point so it follows the mouse cursor? 1 Answer

Rotate One Object Around Another 1 Answer

trying to RotateAround an object around another object using mouse 1 Answer

Using Math to adjust a transforms angle about an axis? 0 Answers

Rotate object around object with fixed value. 1 Answer


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