Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 harrymuana · Jul 09, 2015 at 09:32 AM · c#animationrotatehold

Controlling body parts during animations with scripts

I'm making an archer in a 2D game. I've made an arrow drawing animation which leaves the player aiming in a horizontal direction. I now want the player to move the aiming direction by moving the mouse around. I know how to calculate the aiming angle (from the center of the player).

So the thing I'd like to know is how do I rotate my body parts around to match the direction I am aiming in? This is what I've tried:

I've made a new animation, "hold", which is automatically transitioned to after the arrow draw animation. It is just one frame, and it is a copy of the last frame of the drawing animation. As long as the player holds the mouse, we are in the hold animation. Now I wanted to rotate the right bracer and left arm via scripting, but alas this did not work:

 if (anim.GetCurrentAnimatorStateInfo (0).IsName ("hold")) {
     rightBracer.rotation = Quaternion.Euler(0,0, aimAngle + 474.3156f); // 474. is the rotation when the player is aiming right
     leftArm.rotation = Quaternion.Euler(0,0, aimAngle + 69.52766f);
 }

I've figured out that the reason is probably that the animation clip "hold" is overwriting these changes.

So there's two possible solutions I can think of but I do not know where to start for both of them:

1) There could be a way to directly overwrite the animation or atleast make sure the animation does not overwrite my scripting values.

2) I should delete the hold animation, so my player is no longer in an animation state. But how does this work? Should I make a transition to the "Exit" state in my animator controller? How do I stay in (a modified version of) the last frame of the drawing animation? And how do I go back to animations?

How would you fix this?

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

Answer by Nischo · Jul 09, 2015 at 09:51 AM

I would try to fix this with a blend tree. So have 2 extreme aiming animations for up and down, and use the actual angle to blend between these two values. If necessary you can do that with a 2D blend tree and 4 positions for up/down/left/right aiming.

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 harrymuana · Jul 11, 2015 at 09:39 AM 0
Share

Thank you! I totally missed the blend part of blend trees :O So I thought Id get a discrete set of positions, but obviously there is some blending like the name suggests. Problem solved!

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

2 People are following this question.

avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

How do I rotate my character smoothly? 1 Answer

Distribute terrain in zones 3 Answers

Navigating the 3D platform 0 Answers

Rotate Animation In-Game? 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