Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 LarsAK · Apr 03, 2018 at 11:03 AM · vrspeedeuleranglestransform.rotationrotating

Follow rotation of another object but at half the speed

My problem lies that i want the body to follow the rotation of my head, but at a lower speed. Here is my code.

  public GameObject eyes;
     public GameObject hips;
 
     public float y;
     public Quaternion rotatePos;
     
 
    
     // Use this for initialization
     void Start () {
 
         eyes = GameObject.Find("CenterEyeAnchor");
         hips = GameObject.Find("xbot(Clone)/mixamorig:Hips/mixamorig:Spine/mixamorig:Spine1/mixamorig:Spine2");
         
  
     }
 
     // Update is called once per frame
 
     void Update () {
 
         rotatePos = Quaternion.Euler(0, transform.eulerAngles.y * 0.5f, 0);
         hips.transform.rotation = rotatePos;
         
 
         transform.rotation = eyes.transform.rotation;
  
     }

Now the transform.eulerAngles.y * 0.5f works fine if you go from 0 counting up towards 360 (going right), but as you might guessed if you count down from 0, 360, 359 358.. etc (going left), it automatically goes to 180 due to the calculation.

My problem is i do not know how to set the rotation speed at half of what my head is. Thanks 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

2 Replies

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

Answer by davidcox70 · Apr 03, 2018 at 02:43 PM

Hmmm.

Depending what exactly you need to achieve, would this work maybe?

 hips.transform.rotation=Quaternion.Lerp(eyes.transform.rotation,hips,transform.rotation,0.5f);

Basically, the hips rotation would rotate to be half as rotated as the eyes. Over the same period of time, this would equate to rotating at half the speed whilst always relating to the original origin - i.e. when eyes are faced forward, so is the body.

DC

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 davidcox70 · Apr 03, 2018 at 03:00 PM 1
Share

...on second thoughts;

 Vector3 fixedForward=new Vector3(0,0,1);   // a reference direction
 hips.transform.rotation = Quaternion.LookRotation(Vector3.Lerp(fixedForward,eyes.transform.forward,0.5f));

This rotates the hips half as much as the eyes, with reference to the world's forward direction.

avatar image LarsAK · Apr 04, 2018 at 09:01 AM 0
Share

What i wanted to achieve was a way to control the body of an avatar accordingly to the head when in VR. Your helped worked perfectly thank you ! :)

avatar image
0

Answer by mikewarren · Apr 03, 2018 at 07:00 PM

Your problem is that angles wrap at 360 degrees. I haven't used it, but Mathf.LerpAngle looks like what you might need.

Mathf.LerpAngle

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 LarsAK · Apr 04, 2018 at 09:01 AM 0
Share

Yeah $$anonymous$$athf.LerpAngle was exactly what was necessary. As $$anonymous$$cox70 posted above worked like a charm !

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

104 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 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

Reversing rotation back to zero 0 Answers

How to get Vive Controller Rotation? 0 Answers

Setting Rotations 2 Answers

What's wrong with my if states of eulerAxis.x in Update? 1 Answer

Change rotation of an object based on an HTC Vive Controller 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