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
0
Question by sadowlight123 · May 31, 2017 at 09:59 PM · rotationquaternionaround

Rotation around an Object

Hello all , I am having a hard time understanding what this code does : (it was taken from a tutorial but the explication wasn't clear enough to me) I came to a point where I need this code but with a minor change . I can't change it since I don't understand it well. The goal behind all of it is to make an object rotate around a certain pivot . This object had a predefined position and rotation. The problem with the code as it is is that the object will literally have a big jump from one position and rotation to a completely new position and rotation once the code is activated. It should not jump like that but have a smooth entrance to this code. If you can offer me any kind of help , i'll be really grateful. Thanks for all in advance ! Kindly find the code down below:

//Horz and Vert are random values between -1f and 1f Rotx += Horz Time.deltaTime RotSpeed; Roty += Vert Time.deltaTime RotSpeed; Quaternion Yrot = Quaternion.Euler(0f, Roty, 0f); DestRotation = Yrot Quaternion.Euler(Rotx, 0f, 0f); DestRotation = Quaternion.Euler(Rotx, Roty, 0f); transform.rotation = DestRotation; transform.position = Pivot.position + transform.rotation Vector3.forward * -PivotDistance;

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
0

Answer by UltraSage · Jun 01, 2017 at 05:46 AM

I'll try to break this code down for you:

 //Horz and Vert are random values between -1f and 1f
 Rotx += Horz*Time.deltaTime*RotSpeed;
 //Given Horz is a random number, Rotx is assigned a slowed down RotSpeed value
 Roty += Vert*Time.deltaTime*RotSpeed;
 //Just like above, but with Vert/Roty variables
 Quaternion Yrot = Quaternion.Euler(0f, Roty, 0f);
 //A Quaternion Yrot is declared and assigned Roty value for rotation in y axis
 DestRotation = Yrot*Quaternion.Euler(Rotx, 0f, 0f);
 //Assign multiplied Quaternions to DestRotation. I'm not sure of the outcome but I'm guessing this would return 0, hence Yrot is (0,X,0) and the other quaterion is (X,0,0) and X*0 = 0. This line seems completely useless
 DestRotation = Quaternion.Euler(Rotx, Roty, 0f);
 //This is essentially assigning the quaternion with Rotx and Roty correctly to DestRotation
 transform.rotation = DestRotation;
 //Rotation of DestRotation is assigned to bearer of the script
 transform.position = Pivot.position + transform.rotation*Vector3.forward * -PivotDistance;
 //The position of the bearer of the script is changed after quasi trigonometric calculation

The code is sluggish and complicates the issue. If you simply want to rotate object around some given point, you might want to check out RotateAround() function. With it your script would look like this (In the update function):

transform.RotateAround(Pivot.position,Vector3.up,10f*Time.deltaTime); while: Vector3.up is indicating that the rotation will take place around Y axis. Vector3.forward would be turning around Z axis, and Vector3.right would turn around X axis. and 10f*Time.deltaTime is just a placeholder value, you can set any value you want there. Time.deltaTime helps you to keep rotation consistent with game's framerate.

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

84 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Get rotation around (forward) axis ? 1 Answer

Rotate Rigidbody to always face a force 0 Answers

Problem with normal snapping and rotations. 1 Answer

Relative rotation while moving on parent. 1 Answer

Rotate multiple objects around a object, maintaining their own trajectory(not rotating their local forward vector) 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