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 TheShadyColombian · Aug 30, 2014 at 06:46 PM · animationanimator

the animations on my character are messed up

my character has four animations, but most don't work properly. first, the walking animation only works when the character walks back (Presses S) and the running animation only works when the character runs to the right (Presses D). the idle animation is fine and the death animation up until an eight of the way and then it loops through the next couple of frames until the animation ends. as it is only an eighth of the way no matter what the length is, i just paste the last farm a good 25 seconds, and it plays the beginning fine and the end of it is the same so.. it's not a proper fix but it's a fix. here is my script, hopefully someone notices a difference between the keys and their behaviour so i can fix it, or can tell me if it's something else.

 using UnityEngine;
 using System.Collections;
 
 public class ExperimentalDeath : MonoBehaviour {
 
     public float Health = 100f;
     public float LevelResetTimer = 10f;
     public Animator DeathAnim;
     public AudioClip DeathSound;
     public bool isDead;
     private float timer;
     public GameObject Poof;
     public float maxHealth = 100f;
     public Animator Walk;
     //public Animator Run;
     public float Speed;
     private Animator Fire;
     private bool paused = false;
 
     // Use this for initialization
     void Start () {
     
     }
 
     void Dying () {
         isDead = true;
         DeathAnim.SetBool("isDead", true);
         AudioSource.PlayClipAtPoint(DeathSound, transform.position);
     }
     
     void Dead () {
         Debug.Log("Player Has Died");
         Destroy(gameObject, 3);
         if(Random.Range(0f, 20f)< 1){
             Instantiate (Poof, transform.position, Quaternion.Euler(0f, 0f, Random.Range(0f, 360f)));
         }
     }
 
     void LevelReset () {
         timer =+ Time.deltaTime;
 
         if(timer >= LevelResetTimer){
 
         }
     }
 
     // Update is called once per frame
     void Update () {
         
         if(Input.GetKeyUp(KeyCode.Escape))
         {
             paused = !paused;
         }
         
         //Begin Walking 
 
         
         if (Input.GetKey("w")&& isDead == false && paused == false){
             Walk.SetBool("Walk", true);
             transform.Translate(Vector3.forward * Speed);
         } else {
             Walk.SetBool("Walk", false);
         }
 
 
         if (Input.GetKey("a")&& isDead == false && paused == false){
             transform.Translate(Vector3.left * Speed);
             Walk.SetBool("Walk", true);
         } else {
             Walk.SetBool("Walk", false);
         }
 
         
         if (Input.GetKey("d")&& isDead == false && paused == false){
             transform.Translate(Vector3.right * Speed);
             Walk.SetBool("Walk", true);
         } else {
             Walk.SetBool("Walk", false);
         }
 
         
         if (Input.GetKey("s")&& isDead == false && paused == false){
             transform.Translate(Vector3.back * Speed);
             Walk.SetBool("Walk", true);
         } else {
             Walk.SetBool("Walk", false);
         }
 
 
         
         //Running
         
         if (Input.GetKey("w") && Input.GetKey(KeyCode.LeftShift) && isDead == false && paused == false){
             Walk.SetBool("Run", true);
             transform.Translate(Vector3.forward * Speed);
         } else {
             Walk.SetBool("Run", false);
         }
 
 
         if (Input.GetKey("a") && Input.GetKey(KeyCode.LeftShift) && isDead == false && paused == false){
             Walk.SetBool("Run", true);
             transform.Translate(Vector3.left * Speed);
         } else {
             Walk.SetBool("Run", false);
         }
 
         
         if (Input.GetKey("s") && Input.GetKey(KeyCode.LeftShift) && isDead == false && paused == false){
             transform.Translate(Vector3.back * Speed);
             Walk.SetBool("Run", true);
         } else {
             Walk.SetBool("Run", false);
         }
 
         
         if (Input.GetKey("d") && Input.GetKey(KeyCode.LeftShift) && isDead == false && paused == false){
             Walk.SetBool("Run", true);
             transform.Translate(Vector3.right * Speed);
         } else {
             Walk.SetBool("Run", false);
         }
 
 
         //End of Walking
 
 
 
         if(Health > maxHealth){
             Health = maxHealth;
         }
 
         if(Health <= 0f) {
             if (isDead){
                 Dead ();
                 LevelReset ();
                 isDead = true;
             } else {
                 Dying ();
             }
         }
 
         if(Health != Health){
             Debug.Log (Health);
         }
 
         if (Input.GetKey("x")){
             DamageChar (1);
         }
     }
 
     public void DamageChar (float amount) {
         Health -= amount;
     }
 }


Also, the walk animation plays even if shift is pressed (is running). thanks for reading this and i hope you can help me solve this and have a good day!

Update: death animation fixed by setting "can transition to self" to false (never enabled it myself, i swear :D )

Another Update: It appears only the last if Input.GetKey is the one that play the animation. i moved forwards (W) to the bottom and then only forwards played the animation. also, i used a piece of software and other than the obvious (the key pressed and the direction to move/rotate) they are all the same.

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

1 Reply

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

Answer by TheShadyColombian · Sep 02, 2014 at 10:14 PM

added line after all the sets of Input.getKey that said

 if ((Input.GetKey("w")||Input.GetKey("a")||Input.GetKey("s")||Input.GetKey("d")) && Input.GetKey(KeyCode.LeftShift) && isDead == false && paused == false){
             Walk.SetBool("Run", true);
         } else {
             Walk.SetBool("Run", false);
         }

and so if any of the keys is pressed it plays the animation. for walking i added && !Imput.GetKey(KeyCode.LeftShift) because it was tripping between the walking and running.

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

2 People are following this question.

avatar image avatar image

Related Questions

2D Animation does not start 1 Answer

How to create animations that can be edited with scripts in runtime? 1 Answer

How can I use parameters value in the animation 1 Answer

End of animation with animator. 0 Answers

Why isn't my gun showing up when I play in maximised mode? (Mechanim Animator) 1 Answer


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