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 Wafflebasket · Oct 17, 2019 at 01:39 PM · rotationquaternionchild

Rotating a child transform.

When aiming, I dont want my full character to rotate around the X axis, but only the upper-body. Now I've got the upper-body transform, but I cant seem to rotate it.

Could anyone help me figure this out?

 void Start()
     {
         var hips = transform.Find("mixamorig:Hips");
         upperBody = hips.Find("mixamorig:Spine");
     }

This gets the spine transform through the hips child of the character (I couldn't access it directly, only through hips.)

     if (isAiming)
     {
         var xMouse = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier;
         upperBody.Rotate(0, xMouse, 0);

         var yMouse = -Input.GetAxis("Mouse Y") * turnSpeed * mouseTurnMultiplier;
         upperBody.Rotate(yMouse, 0, 0);
     }

This does not rotate the upper-body of the character, and I'm stumped as to how. I have no constraints on the parent either.

Would greatly appreciate help with this!

Comment
Add comment · Show 4
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 KhalilAboid · Oct 17, 2019 at 02:51 PM 0
Share

Are you sure that you are putting that snippet in the update? anyway, have you checked that upperBody is what you really want by logs? Try to log y$$anonymous$$ouse and x$$anonymous$$ouse too to see what could be happening.

avatar image Wafflebasket KhalilAboid · Oct 17, 2019 at 04:21 PM 0
Share

I did all you suggested trying to figure out my issue, before co$$anonymous$$g here, yes.

avatar image GoneMadStudios · Oct 17, 2019 at 03:24 PM 1
Share

Do you have an Animator attached to this GameObject? When a Transform is part of an animation, you can't move it by script.

avatar image Wafflebasket GoneMadStudios · Oct 17, 2019 at 04:03 PM 0
Share

There is indeed an Animator attached, that makes sense! Thanks for answering my question. Follow-up tho, is there a workaround? Currently looking at unity animations. If anyone has any tips as to where i can pick up some info on this matter, greatly appreciated!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GoneMadStudios · Oct 22, 2019 at 06:37 PM

As you can see in Unity's script lifecycle, animations are processed after scripts' Update() functions are called:

alt text

This means that all changes you make in Update() are overriden by the animator, so you have to do the changes after ProcessAnimation(). You can use LateUpdate() to change Transforms or use OnAnimatorIK(), but this function is only called if the script is in the same GameObject in hierarchy as the Animator.


unitycycle.png (28.3 kB)
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

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

Rotation issue with remote players projectiles 0 Answers

How to fix Child Object Rotations.? 1 Answer

Child versus Parent rotations 3 Answers

force child rotation to zero? 2 Answers

Rotating an object so that the direction between it's children matches the forward of rotating object 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