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 pepefirst · May 28, 2011 at 02:16 PM · animations

Animations do not perform

In my game I have 3 animations, idle, walk and jump. I prepared them in Maya and exported to Unity in the form Character@idle, Character@walk, Character@jump. They show OK in the Inspector. I put idle as my reference and dragged Character@idle to the scene. I added all the required elements in the Hierarchy and the Inspector, and selected the 3 animations there. When I hit Play the idle is performed by the Character but when I move it I get a sliding movement of the Character (i.e. it do not performs the walk cycle)

Any help?

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

4 Replies

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

Answer by pepefirst · May 29, 2011 at 01:26 PM

Finally I noticed that I was dragging the Character from the Project window instead of dragging him from the Hierarchy window to the animation reference field in the AnimationController script AND in the AnimationSpeed script . THAT WAS THE ERROR!!! In the respective item into the hierarchy is where one works adding components to it and therefore, this is the item that have all the parts (including the animation list) that content the wanted properties. SOLVED!

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 KennSan · May 28, 2011 at 05:01 PM

Without seeing any code that you're using it's hard to narrow down the issue. However my first port of call would be to check that it's even calling the idle animation as the animation portion of the inspector will generally play idle by default.

I would change the animation that it's calling to either jump or walk. If it's playing the animation to begin with automatically it means that it's having trouble calling anything. I'm hardly a pro coder but if you post the code you're using to call it I'll have a look-see :)

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 pepefirst · May 28, 2011 at 05:25 PM

This is the code. Nothing original. It is an adaptation of Penelope game script. Thanks for your interest in helping me to solve this problem.

////////////////////////////////////////////////////////////// // AnimationController.js // // // AnimationController plays the appropriate animations // and the blending between them. It uses the character's // movement direction to determine which animation should be played. //////////////////////////////////////////////////////////////

// The Animation component that this script controls var animationTarget : Animation;

// Different speeds depending on movement direction var maxForwardSpeed : float = 6; var maxBackwardSpeed : float = 3; var maxSidestepSpeed : float = 4;

private var character : CharacterController; private var thisTransform : Transform; private var jumping : boolean = false; private var minUpwardSpeed = 2;

function Start() { // Cache component lookup at startup instead of doing this every frame character = GetComponent( CharacterController ); thisTransform = transform;

 // Set up animation settings that aren't configurable from the editor
 animationTarget.wrapMode = WrapMode.Loop;
 animationTarget[ "jump" ].wrapMode = WrapMode.ClampForever;
 //animationTarget[ "jump-land" ].wrapMode = WrapMode.ClampForever;
 //animationTarget[ "run-land" ].wrapMode = WrapMode.ClampForever;
 //animationTarget[ "LOSE" ].wrapMode = WrapMode.ClampForever;

}

function OnEndGame() { // Don't update animations when the game has ended this.enabled = false; }

function Update() {
var characterVelocity = character.velocity;

 // When monitoring movement we check horizontal and vertical movement 
 // separately to decide what animations to play.
 var horizontalVelocity : Vector3 = characterVelocity;
 horizontalVelocity.y = 0; // ignore any vertical movement
 var speed = horizontalVelocity.magnitude;

 var upwardsMotion = Vector3.Dot( thisTransform.up, characterVelocity );
 
 if ( !character.isGrounded && upwardsMotion > minUpwardSpeed )
     jumping = true;
 
 /*
 if ( animationTarget.IsPlaying( "run-land" )
     && animationTarget[ "run-land" ].normalizedTime < 1.0
     && speed > 0 )
 {
     // Let this animation finish
 }
 else if ( animationTarget.IsPlaying( "jump-land" ) )
 {
     // Let this animations finish
     if ( animationTarget[ "jump-land" ].normalizedTime >= 1.0 )
         // when the animation is done playing, go back to idle
         animationTarget.Play( "idle" );        
 }
 else */if ( jumping )
 {
     if ( character.isGrounded )
     {
         /*
         // play the appropriate animation for landing depending on
         // whether we are landing while running or jumping in-place 
         if ( speed > 0 )
             animationTarget.Play( "run-land" );
         else    
             animationTarget.Play( "jump-land" );
         */
         jumping = false;                
     }
     else
         animationTarget.Play( "jump" );
 }
 else if ( speed > 0 )
 {
     var forwardMotion = Vector3.Dot( thisTransform.forward, horizontalVelocity );
     var sidewaysMotion = Vector3.Dot( thisTransform.right, horizontalVelocity );
     var t = 0.0;
     
     // Use the largest movement direction to determine which animations to play
     if ( Mathf.Abs( forwardMotion ) > Mathf.Abs( sidewaysMotion ) )
     {
         if ( forwardMotion > 0 )
         {
             // Adjust the animation speed to match with how fast the
             // character is moving forward
             t = Mathf.Clamp( Mathf.Abs( speed / maxForwardSpeed ), 0, maxForwardSpeed );
             //animationTarget[ "run" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
                                     
             if (/* animationTarget.IsPlaying( "run-land" ) || */animationTarget.IsPlaying( "idle" ) )
                 // Don't blend coming from a land, just play
                 //animationTarget.Play( "run" );
                 animationTarget.Play( "walk" ); 
             else
                 //animationTarget.CrossFade( "run" );
                 animationTarget.CrossFade( "walk" );
         }
         else
         {
             // Adjust the animation speed to match with how fast the
             // character is moving backward
             t = Mathf.Clamp( Mathf.Abs( speed / maxBackwardSpeed ), 0, maxBackwardSpeed );
             
             /*
             animationTarget[ "runback" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget.CrossFade( "runback" );
             */
             animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget.CrossFade( "walk" );    
         }
     }
     else
     {
         // Adjust the animation speed to match with how fast the
         // character is side-stepping            
         t = Mathf.Clamp( Mathf.Abs( speed / maxSidestepSpeed ), 0, maxSidestepSpeed );

         if ( sidewaysMotion > 0 )
         {
             /*
             animationTarget[ "runright" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget.CrossFade( "runright" );
             */
             animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget.CrossFade( "walk" );                
         }
         else
         {
             /*
             animationTarget[ "runleft" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget.CrossFade( "runleft" );
             */
             animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
             animationTarget.CrossFade( "walk" );
         }
     }
 }
 else
     // Play the idle animation by default
     animationTarget.CrossFade( "idle" );

}

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 KennSan · May 28, 2011 at 11:42 PM

Hmm... is there any special variables that you need to consider for the animations? (eg. animation speeds altering or whatnot) as if it's just a standard call to animation you could look at the project I'm working on at the moment is using this method to call animations:

if (!animation.IsPlaying(AnimationName.name)){ animation.Play(AnimationBane.name);

(So basically if it's not playing that animation, begin to play it)

and for actions that the animation need to finish before they continue, yield the animation script so it holds until the animation is finished:

yield WaitForSeconds (AnimationName.length);

With my project however the animations are set to AnimationClip variables set up on the code so if your animations are called in a different way you should be able to work a method to adapt it so it works for you.

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 KennSan · May 28, 2011 at 11:43 PM 0
Share

Bah with the first example for some reason it posted it as one line, so the second line begins after the {

Sorry for my delay in reply

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

Animation transform and player position issue 0 Answers

Lane moving vehicle 1 Answer

Animator switching between floats 1 Answer

How to get blended animations into the scene 0 Answers

Animations and Rotation of character 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