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 MachCUBED · Dec 11, 2011 at 04:45 AM · animationblenderexport

Some animations aren't playing in Unity 3.4.2

Hello everyone,

I have a player character whose movement works just fine along both the horizontal and vertical axis. Moreover, the character's walk animation works as expected, with all crossfading working as it normally would given that all the model's animation wrap mode is loop. However, the character's punch and kick animations are not playing at all when the relevant buttons are pressed. Here is my PlayerAttack.js script:

 var punchSpeed = 1;
 var punchHitTime = 0.2;
 var punchTime = 0.4;
 var punchPosition = new Vector3 (0, 0, 0.8);
 var punchRadius = 1.3;
 var punchHitPoints = 1;
 
 var kickSpeed = 1;
 var kickHitTime = 0.2;
 var kickTime = 0.4;
 var kickPosition = new Vector3 (0, 0, 0.8);
 var kickRadius = 1.3;
 var kickHitPoints = 1;
 
 var bashSound : AudioClip;
 
 private var busy = false; 
 
 function Start ()
 {
     animation["punch_r"].speed = punchSpeed;    
     animation["kick_r"].speed = kickSpeed;
 }
 
 function Update ()
 {
     var controller : ThirdPersonController = GetComponent(ThirdPersonController); 
     if(!busy && Input.GetButtonDown("Punch"))
     {    
         SendMessage ("DidPunch");
         busy = true;
     }
     if(!busy && Input.GetButtonDown("Kick"))
     {    
         SendMessage ("DidKick");
         busy = true;
     }
 }
 
 function DidPunch ()
 {
  Debug.Log("Punching...");
     animation.CrossFadeQueued("punch_r", 0.1, QueueMode.PlayNow);
     yield WaitForSeconds(punchHitTime);
     var pos = transform.TransformPoint(punchPosition);
     
     yield WaitForSeconds(punchTime - punchHitTime);
     busy = false;
 }
 
 function DidKick ()
 {
 Debug.Log("Kicking...");
     animation.CrossFadeQueued("kick_r", 0.1, QueueMode.PlayNow);
     yield WaitForSeconds(kickHitTime);
     var pos = transform.TransformPoint(kickPosition);
     
     yield WaitForSeconds(kickTime - kickHitTime);
     busy = false;
 }

The Debug.Log() messages for each attack show up just fine in the console, so I'm 99% certain that it's not a code issue. However, since I checked All Animations in Blender when I exported my .fbx file from Blender 2.5.7 to Unity 3.4.2, I can't figure out how it can be an issue with my Blender file. Any and all help will be appreciated.

MachCUBED

Comment
Add comment · Show 7
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 funkyllama · Dec 11, 2011 at 03:13 PM 0
Share

Have you tried setting your characters default animation to punch & kick. This will show you whether the animations are working or not.

avatar image MachCUBED · Dec 11, 2011 at 04:02 PM 0
Share

I tested the animations by changing the animation name in the following code from my Player$$anonymous$$ovement.js script:


if (Input.GetAxis("Vertical") > 0.1 || Input.GetAxis("Horizontal") > 0.1 || Input.GetAxis("Vertical") < -0.1 || Input.GetAxis("Horizontal") < -0.1)
animation.CrossFade("run");
else
{
animation.CrossFade("idle");
}
}

to play my punch and kick animations during player movement. The animations worked just fine, so it's definitely not an animation problem. Therefore, it must be a code problem.

avatar image funkyllama · Dec 11, 2011 at 04:21 PM 0
Share

I assume this script is attached to the object that has the animations?

avatar image MachCUBED · Dec 11, 2011 at 04:23 PM 0
Share

Yes, both Player$$anonymous$$ovement.js and PlayerAttack.js are attached to the object with the relevant animations.

avatar image funkyllama · Dec 11, 2011 at 04:32 PM 0
Share

I assume as you are using Send$$anonymous$$essage("DidPunch"); that you also have a DidPunch function in your Player$$anonymous$$ovement.js script. Do you also have a Debug.Log("Punching...") in that function. If you do, remove it just to eli$$anonymous$$ate the debug log co$$anonymous$$g from there.

Show more comments

2 Replies

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

Answer by Bunny83 · Dec 11, 2011 at 06:49 PM

I guess your animations work all on the same layer, therefore if you start one of your attack animations it propably gets directly overridden by your movement script. You should set your attack animations to a higher layer so they have a higher priority. If they are finished the movement animation will come back automatically.

Btw. Animation.CrossFadeQueued has some side effects due to duplicating the AnimationState. Only use it if you really need it. CrossFade should be enough in most cases.

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
avatar image
0

Answer by MachCUBED · Dec 11, 2011 at 07:27 PM

Bunny83 and funky llama are right, fixing the Start() function in PlayerAttack.js like so:

function Start () { animation["punch_r"].speed = punchSpeed; animation["kick_r"].speed = kickSpeed;

 animation["punch_r"].wrapMode = WrapMode.Once;
 animation["kick_r"].wrapMode = WrapMode.Once;
 
 animation["punch_r"].layer = 1;
 animation["kick_r"].layer = 1;

}

Fixed everything. Now, the attack animations work as they should. Thank you guys for the help!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Blender import animation to Unity, source take section missing 4 Answers

Blender and unity 1 Answer

Waving flag animation in blender to unity 1 Answer

Problem in Game mode with animation 0 Answers

Blender FBX import problem 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