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
0
Question by smirlianos · Dec 26, 2013 at 11:48 AM · animationattackrunmerge

Merge 2 animations?

Hello,

I try to make a third person game in which you control this character: Warrior

He uses 3 animations: idle,run,attack

The problem is that as my character is walking, he plays the "run" animation. As soon as I click the corresponded button for the attack, he plays the "attack" animation.

However, on the "attack" animation the legs are not moving and it is odd.

Is there any way I can continue to play the "run" animation only on his legs as the upper body part plays the "attack" animation?

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

1 Reply

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

Answer by TonyLi · Dec 26, 2013 at 03:34 PM

Yes, you can do this in both the legacy and Mecanim animation systems.

In Legacy, you'll want to leave "idle" and "run" on layer 0, and put "attack" on layer 1. The "attack" animation on layer 1 will only affect the upper body, using what's called a mixing transform. Script Reference. For example:

 //(Based on the example in the script reference above.)
 
 function Start () {
    // Set all animations to loop
    animation.wrapMode = WrapMode.Loop;
    // except attack
    animation["attack"].wrapMode = WrapMode.Once;
 
    // Put idle and walk into lower layers (The default layer is always 0)
    // This will do two things
    // - Since attack and idle/run are in different layers they will not affect
    //   each other's playback when calling CrossFade.
    // - Since attack is in a higher layer, the animation will replace idle/walk
    //   animations when faded in.
    animation["attack"].layer = 1;

    // Adds a mixing transform so attack uses only upper body:
    var mixTransform : Transform = transform.Find("root/hips/spine2");
    animation["attack"].AddMixingTransform(mixTransform);
 
    // Stop animations that are already playing
    //(In case user forgot to disable play automatically)
    animation.Stop();
 }
 
 function Update () {
    // Based on the key that is pressed,
    // play the walk animation or the idle animation
    if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
       animation.CrossFade("run");
    else
       animation.CrossFade("idle");
 
    // Shoot
    if (Input.GetButtonDown ("Fire1"))
       animation.CrossFade("attack");
 } 


In Mecanim, you'll do something similar, but it's easier. You'll once again use layers. Put idle and run on Layer 0, and attack on Layer 1 with an avatar body mask for the upper body only.

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 smirlianos · Dec 26, 2013 at 04:27 PM 0
Share

Big thanks man! It worked like a charm! :D

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

19 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

Related Questions

8-Way Animation Blending 2 Answers

How to fix rig animation that stops short when increasing speed? 0 Answers

Can I make animations snap to a frame? 1 Answer

Call a function dependent on frame of animation? 2 Answers

What is the best way to manage the attack and auto-attack animation per second when the object collides?,Best way to make 2 objects attack per time each other when colide? 0 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