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 dylan56477 · Dec 31, 2011 at 09:45 PM · animationplaystopcrossfade

Animation problem in script

Sry bout all these newbie questions guys lol. Anyways, I have these animations for walking and sprinting. I have it so when u press the w key it loops and when u let the button go. Ok so that works perfectly, but when I tried to do that with sprinting it doesn't run either animation. What's up with that? Here's my code. It's a modify of the Character motor script on the FPC:

 var walkSpeed: float = 7; // regular speed
 
 var crchSpeed: float = 3; // crouching speed
 
 var runSpeed: float = 20; // run speed
 
 
 
 private var chMotor: CharacterMotor;
 
 private var tr: Transform;
 
 private var dist: float; // distance to ground
 
 
 
 function Start(){
 
     chMotor = GetComponent(CharacterMotor);
 
     tr = transform;
 
     var ch:CharacterController = GetComponent(CharacterController);
 
     dist = ch.height/2; // calculate distance to ground
 
 }
 
 
 
 function Update(){
 
 
 
     var vScale = 1.0;
 
     var speed = walkSpeed;
 
     
 
     if (Input.GetKey("left shift") || Input.GetKey("right shift")){
 
         if (Input.GetKey(KeyCode.W))
 
         {
 
         speed = runSpeed;
 
         GameObject.Find("FPS_m16").animation.Stop("Walking");
 
         GameObject.Find("FPS_m16").animation.CrossFade("Sprinting");
 
         }
 
     }
 
     if (Input.GetKey("left shift") || Input.GetKey("right shift"))
 
     {
 
         GameObject.Find("FPS_m16").animation.Stop("Sprinting");    
 
     }
 
     
 
     if (Input.GetKey("c")){ // press C to crouch
 
         vScale = 0.5;
 
         speed = crchSpeed; // slow down when crouching
 
     }
 
     if (Input.GetButtonDown("Walk")){
 
         GameObject.Find("FPS_m16").animation.CrossFade("Walking");
 
     }
 
     if (Input.GetButtonUp("Walk")){
 
         GameObject.Find("FPS_m16").animation.Stop("Walking");
 
     }
 
     chMotor.movement.maxForwardSpeed = speed; // set max speed
 
     var ultScale = tr.localScale.y; // crouch/stand up smoothly 
 
     tr.localScale.y = Mathf.Lerp(tr.localScale.y, vScale, 5*Time.deltaTime);
 
     tr.position.y += dist * (tr.localScale.y-ultScale); // fix vertical position
 }

Thanks!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Animation Crossfade won't play but Animation Play does 1 Answer

Detect if is playing an animation 1 Answer

Automatically playing animations 1 Answer

Walking Animation 1 Answer

Walking animation has wrong rotation 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