Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 13dnizinski · Jan 04, 2014 at 05:37 AM · animationanimatoranimator controllerfreezemechanim

Why do my animations only play once?

Hello, today was my first time using the animator object. With the script I applied, the model goes through its correct animation once and then freezes in the first frame of that animation. I know as a fact, the "Speed" parameter of the animator object is changed correctly; I see it change whenever I press an input button. For example, when using my Walk animation, the model freezes just after completed a full walk cycle. What am I doing wrong? Does this have something to do with the animations themselves? Thanks in advance!

Here's my code: using UnityEngine; using System.Collections; using System.Collections.Generic;

public class FirstPersonController : MonoBehaviour { public Animator animatorComponent; private HashIDs hashComponent;

 float walkSpeed = 10;
 float gravity = 100;
 private float yRot;    
 private float xRot;    
 public Camera mainCam;
 public CharacterController controller;
 public GameObject characterMesh;
 float deltaVelocity = 0;
 float cameraRotation;
 //The following are for the jumpscript
 bool canJump;
 int xValue;
 public int jumpHeight;
 GameObject player;
 
 void Start() {
     player = GameObject.Find("Player");
     canJump = true;
     animatorComponent = GameObject.FindGameObjectWithTag("PlayerMesh").GetComponent<Animator>();
     hashComponent = GetComponent<HashIDs>();
     animatorComponent.SetLayerWeight(1, 1f);
 }
 
 void Update(){    
     Vector3 vertical = transform.TransformDirection(Vector3.forward);
     Vector3 horizontal = transform.TransformDirection(Vector3.right);    
     Vector3 height = transform.TransformDirection(Vector3.up);
     walkSpeed = 0;//Updates the character's speed

     //basic jumping
     if(Input.GetAxis("Jump") > 0 && canJump) {
         xValue = -1 * jumpHeight;
         StartCoroutine(basicJump());
     }
     
     //Receive Mouse Input        
     if(Input.GetAxis("Mouse X") != 0) {
         yRot = Mathf.SmoothDamp(yRot, yRot + Input.GetAxis("Mouse X"), ref deltaVelocity, .03f);
     }
     
     if(Input.GetAxis("Mouse Y") != 0) {
         xRot -= Input.GetAxis("Mouse Y");
     }
     
     
     Screen.lockCursor = true;//Puts the mouse in the screen's center
     transform.rotation = Quaternion.Euler(0, yRot, 0);        
     //Moves the camera, rotate character
     mainCam.transform.rotation = Quaternion.Euler(xRot, yRot, 0);
     
     controller.Move((height * (-gravity) * Time.deltaTime)/5);
     
     
     if(Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0) {
         //characterMesh.animation.CrossFade("Run");
         if(Input.GetAxis("Vertical") != 0) {
             walkSpeed = 10 * Input.GetAxis("Vertical");
             controller.Move( (float)(walkSpeed * Time.deltaTime)* vertical);
         }
         if(Input.GetAxis("Horizontal") != 0) {
             walkSpeed = 10 * Input.GetAxis("Horizontal");
             controller.Move( (float)(walkSpeed * Time.deltaTime) * horizontal);
         }
         animatorComponent.SetFloat("Speed", Mathf.Abs(walkSpeed) );
         //Moves the actual character
     } else {
         //characterMesh.animation.CrossFade("Idle");
         //This segment assumes that variable 'walkSpeed' is set to zero
         animatorComponent.SetFloat("Speed", walkSpeed);
     }
 }
 
 IEnumerator basicJump() { //NOTE TO SELF:  REFINE THIS
     canJump = false;
     for(var i = 0; i < jumpHeight; i++) {
         gravity = (-.05f) * (xValue * xValue);
         xValue++;
         yield return new WaitForSeconds(.001f);
     }
     
     
     for(var j = jumpHeight; j > 0; j--) {
         gravity = (.05f) * (xValue * xValue);
         xValue--;
         yield return new WaitForSeconds(.001f);
     }
     
     yield return new WaitForSeconds(.3f);
     canJump = true;
 }

}

Comment
Add comment · Show 2
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 KuPAfoo · Jan 04, 2014 at 06:05 AM 0
Share

I know for Input.Get$$anonymous$$ey you need to use Input.Get$$anonymous$$eyDown to repeat...

avatar image 13dnizinski · Jan 04, 2014 at 06:56 AM 0
Share

I don't think the input is the problem, since the values are changed in the Animator window whenever I hold down the input keys.

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by 13dnizinski · Jan 04, 2014 at 07:36 AM

Thanks for the help, KuPAfoo! I solved the problem - I had to check a box that said "Loop Time" when I imported. I have no clue what it does, but it fixed my problem!

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 KuPAfoo · Jan 04, 2014 at 05:29 PM 0
Share

Well done :)

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

How to change animation clips of an animator state at runtime? Is there a way? 5 Answers

Get weird issue when change from Mechanim -> Ragdoll 0 Answers

Can animation clips be swapped out of the animator override controller in runtime? 1 Answer

Wrap Mode in animator not working properly 0 Answers

Display additional animation on top of other animations 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