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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by CyberArtist · Aug 24, 2014 at 09:44 PM · animationjavascriptwrapmode

Fall Animaion ClampForever won't unclamp when grounded.

I'm keep editing my scripts in order to make my FallDown clip work properly. When the WrapMode is set to ClampForever, it won't allow any animation to play when my character is grounded (moveDirection.y < -1). Is there something I'm missing, or do negative integers not work? I know there are other tutorials on character scripting, but I'll have to rewrite my animation script, controller script, and possibly other scripts. Is there somewhere I can make the proper editing without a lot of rework?

Here's a major chunk from both scripts.

 function Start()
 {
     //Set up layers - high numbers recieve priority when blending
     animation["Idle"].layer = 0;
     //We want to make sure that the (animations) are synced together
     animation["Walk"].layer = 1;
     animation["Run"].layer = 1;
     animation["Crouch"].layer = 1;
     animation.SyncLayer(1);
     
     animation["KickA"].layer = 3;
     animation["Jump"].layer = 5;
     //These should take priority over all others
     animation["FallDown"].layer = 7;
     animation["GetHit"].layer = 8;
     animation["Death"].layer = 10;
     
     animation["Crouch"].wrapMode = WrapMode.Loop;
     animation["Jump"].wrapMode = WrapMode.Once;
     animation["FallDown"].wrapMode = WrapMode.ClampForever;
     
     //Make sure nothing is playing by accident, then start with a default idle.
     animation.Stop();
     animation.Play("Idle");
 }
 
 function Update() 
 {
     //On  the ground animations
     if(playerController.IsGrounded())
     {
 
         //If Running
         if(playerController.IsRunning())
         {
             animation.CrossFade("Run", 0.5);
             animation["Run"].speed = 4.4;
             nextPlayIdle = Time.time + waitTime;
         }
         else if(playerController.IsCrouching())
         {
             animation.CrossFade("Crouch", 0.2);
             nextPlayIdle = Time.time + waitTime;
         }
         //Fade in Walk
         else if(playerController.IsMoving())
         {
             animation.CrossFade("Walk", 0.5);
             animation["Walk"].speed = 3.2;
             nextPlayIdle = Time.time + waitTime;
         }
         //Fade out walk and run else
         else
         {
             animation.Blend("Run", 0.0, 0.3);
             animation.Blend("Walk", 0.0, 0.3);
             animation.Blend("Crouch", 0.0, 0.3);
             if(Time.time > nextPlayIdle)
             {
                 nextPlayIdle = Time.time + waitTime;
                 PlayIdle();
             }
         }
     }
     //In air animations
     else
     {
         if(Input.GetButtonDown("Jump"))
         {
             animation.CrossFade("Jump");
             animation["Jump"].speed = 3;
         }
         
         if(!playerController.IsGrounded() && playerController.moveDirection.y < -1)
         {
             animation.CrossFade("FallDown", 0.5);
             animation["FallDown"].speed = 3;
         }
         if(playerController.IsGrounded() && playerController.moveDirection.y > -1)
         {
             animation.CrossFade("Idle");
         }
     }
     
     //Test for idle
     if(Input.anyKey)
     {
         if(playerController.moveDirection.magnitude >= 0 && playerController.IsGrounded())
         {
             animation.CrossFade("Idle");
         }
     }
 }


//////////////////////////////////////////////////////////////////////////////////////

 var walkSpeed = 2.0;
 var runSpeed = 2.0;
 var jumpSpeed = 8.0;
 var gravity = 9.0;
 var rotateSpeed = 4.0;
 var crouchSpeed = 0.5;
 
 var isControllable : boolean = true;
 
 //Private, helper variables
 var moveDirection = Vector3.zero;
 private var grounded : boolean = false;
 private var inAir : boolean = false;
 private var moveHorz = 0.0;
 private var normalHeight = 2.0;
 private var crouchHeight = 1.7;
 private var rotateDirection = Vector3.zero;
 
 private var isCrouching : boolean = false;
 private var isRunning : boolean = false;
 
 //Cache controller so we only have to find it once
 var controller : CharacterController;
     controller = GetComponent(CharacterController);
 var MoaliaStatus : Moalia_Status;
 MoaliaStatus = GetComponent(Moalia_Status);
 
 //Move the controller during the fixed frame updates
 function FixedUpdate()
 {
     if(!isControllable)
         Input.ResetInputAxes();
 
     else
     {
         if(grounded)
         {
             //Since we're touching something solid, such as the ground, allow movement
             //Calculate movement directly from input axes
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= walkSpeed;
             moveDirection.y -= gravity * Time.deltaTime;
             
             //Find rotation based upon axes if need to turn
             moveHorz = Input.GetAxis("Horizontal");
             if (moveHorz > 0)    //Right turn
                 rotateDirection = new Vector3(0, 1, 0);
             else if (moveHorz < 0)    //Left turn
                 rotateDirection = new Vector3(0, -1, 0);
             else    //not turning
                 rotateDirection = new Vector3(0, 0, 0);
                 
             if(inAir)
             {
                 inAir = true;
             }
             
             //Jump controls    
             if(Input.GetButton("Jump"))
             {
                 if(Input.GetButton("Run") && Input.GetButton("Jump"))
                 {
                     moveDirection.y = jumpSpeed/2;
                 }
                 else
                 {
                     moveDirection.y = jumpSpeed;
                 }
             }

   

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Playing sprint animation with vertical axis? 0 Answers

How to fix Animation 1 Answer

Why isn't my animation being played? 0 Answers

Changing number of frames in uvAnimationTileX 0 Answers

Using animationState for animation controls 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