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
1
Question by Cogs and Ink · Apr 08, 2014 at 02:26 PM · animationrotationroot motion

Animations preventing rotation

Hello,

I am making a 2D top-down game in which the player object moves along the X and Y axes and rotates in the Z axis. The player object has two animations: "Idle", which has no curves, and "Move", which contains only a Sprite Renderer Colour curve (the player flashes different colours as they move). Transitions between these two states are controlled by an animator bool 'moving', which is set in the player's Update method - sample code:

 anim.SetBool("moving",true);

This system works perfectly. However, I also wanted the player object to rotate to face the current direction. To make this happen I added this code to the end of its Update method:

 float targetAngle = Mathf.Atan2(moveDirection.y, moveDirection.x) * Mathf.Rad2Deg;
 transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 0, targetAngle), turnSpeed * Time.deltaTime);

This code also works. The problem I have is that it only works if the Animator for the player prefab is disabled in the inspector, and I cannot make both the animations (which, again, have no rotation component) and the rotation code work. If the animator is enabled, the animations work and the player's rotation does not change; if the animator is disabled the rotation changes as it should but (obviously) the animations do not play. How can I make them work together?

P.S. I'm aware of root motion and baking; I've tried every possible combination of options, including 'Bake into Pose', 'Loop Pose' and 'Based Upon (at Start)' in the animation options and 'Apply Root Motion' in the Animator settings. None of these have any visible effect. The closest I've got is by checking 'Animate Physics' in the Animator settings, which causes the rotation to start but be reset by each loop of the 'Move' animation, meaning that the player object is constantly shuddering between two angles.

Comment
Add comment · Show 1
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 Cogs and Ink · Apr 08, 2014 at 01:10 PM 0
Share

Ok, so I sort-of-solved this myself by creating a child object for the player and outsourcing all the animation to it. This meant writing quite a lot of new code to pass methods back and forth between the parent and the child and so on, but it works. If there's a more elegant solution I'd love to hear it.

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Matching character's rotation to the rotation of a animation - How? 0 Answers

How to do Turn animations with root motion (root bone rotations)? 2 Answers

Animation stops too early on all keyframes with apply root motion 1 Answer

Mecanim Root Motion Rotation - 180 degree turn. 2 Answers

Root Motion slowly veers off track 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