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 Sujetsi · Oct 16, 2018 at 12:40 AM · c#animationcharactercontrollerfbxidle

Idle Animation fighting/overriding other ground animations

Currently my Idle animation is overriding other animations other than the running one due to it being inside a boolean statement. If I try to play the RPunch animation it will flash for a bit then quickly go back to the idle animation. What should I do about this and other future ground animations?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
  
 public class PlayerCharacterController: MonoBehaviour {
  
     static Animator anim;
  
     public bool walking;
 
     public GameObject playerModel, Hero;
     //Transforms
     public Transform playerCam, character, centerPoint;
 
     private Vector3 moveDirection;
 
     //character controller declaration
     CharacterController player;
  
     //Mouse Rotation
     private float rotX, rotY;
     //Mouse Y Position
     public float mouseYPosition = 1f; 
     //Mouse Sensitivity
     public float Sensitivity = 10f;
     //Mouse Zoom
     private float zoom;
     public float zoomSpeed = 2;
     //Clamping Zoom
     public float zoomMin = -2f;
     public float zoomMax = -10f;
     public float rotationSpeed = 5f;
     //Move Front Back left & Right
     private float moveFB, moveLR;    
     //Movement Speed
     public float Speed = 2f;
     //Velocity of Gravity
     public float verticalVelocity;
     //Jump Distance
     public float jumpDist = 5f;
     //Multiple Jumps
     int jumpTimes;
     //To use with Dialogue Manager
     public DialogueManager DiagM;
 
     public AudioClip jumpSound;
     public AudioClip HurtSound;
 
     AudioSource audioSource;
 
     //knockback
 
     public float knockBackForce;
     public float knockBackTime;
     private float knockBackCounter;
 
 
     // Use this for initialization
     void Start ()   
     {
         //character controller
         player = GameObject.Find("Player").GetComponent<CharacterController> ();
  
         anim = GetComponent<Animator>();
       
         //mouse zoom
         zoom = -3;    
         centerPoint.transform.position = playerCam.transform.position;
         centerPoint.transform.parent = null;
         audioSource = GetComponent<AudioSource>();
     }
  
     // Update is called once per frame
  
     void Update ()
  
     {        
         //Mouse Zoom Input
         zoom += Input.GetAxis ("Mouse ScrollWheel") * zoomSpeed;
         if (zoom > zoomMin)
             zoom = zoomMin;
         if (zoom < zoomMax)
             zoom = zoomMax;
  
         //Mouse Camera Input
         playerCam.transform.localPosition = new Vector3 (0, 0, zoom);
  
         //Mouse Rotation
                                
         rotX += Input.GetAxis ("Mouse X") * Sensitivity;
         rotY -= Input.GetAxis ("Mouse Y") * Sensitivity;      
  
         //Clamp Camera
         rotY = Mathf.Clamp (rotY, -60f, 60f);
         playerCam.LookAt (centerPoint);
         centerPoint.localRotation = Quaternion.Euler (rotY, rotX, 0);
 
         //Movement Speed
         if (knockBackCounter <= 0)
      {   
         moveDirection = (transform.forward * Input.GetAxis("Vertical")) + (transform.right * Input.GetAxis("Horizontal"));
         moveDirection = moveDirection * Speed;
         moveDirection.y = verticalVelocity;
 
         player.Move(moveDirection * Time.deltaTime);
         
         
  
         //Movement Rotation
 
         centerPoint.position = new Vector3 (character.position.x, character.position.y + mouseYPosition, character.position.z);
 
             //knockback disable
             //Movement Input
 
             if (Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)
 
             {
                 transform.rotation = Quaternion.Euler(0f, centerPoint.rotation.eulerAngles.y, 0f);
                 Quaternion turnAngle = Quaternion.LookRotation(new Vector3(moveDirection.x, 0f, moveDirection.z));
                 playerModel.transform.rotation = Quaternion.Slerp(playerModel.transform.rotation, turnAngle, Time.deltaTime * rotationSpeed);
 
                 if (player.isGrounded == true)
 
                 {
                     anim.SetBool("isWalking", true);
                     anim.Play("Running");
                 }
             }
             else if (player.isGrounded == true)
                 {
                     anim.SetBool("isWalking", false);
                     anim.Play("Idle");
                 }
             
              if (Input.GetButtonDown("LHand"))
                 {                              
                     anim.Play("RPunch");                                   
                 }
 
            
 
         
 
             if (player.isGrounded == true)
 
             {
                 jumpTimes = 0;
                 verticalVelocity = -Physics.gravity.y * Time.deltaTime;
             }
 
             else
 
             {
                 verticalVelocity += Physics.gravity.y * Time.deltaTime;
                 anim.SetBool("isWalking", false);
                 anim.SetBool("isFalling", true);
             }
 
           
 
             if (jumpTimes < 1)
 
             {
                 if (Input.GetButtonDown("Jump"))
                 {
                     verticalVelocity += jumpDist;
                     anim.Play("Jump");
                     audioSource.PlayOneShot(jumpSound, 1F);
                     jumpTimes += 1;
                 }
             }
         }
         else
         {
             knockBackCounter -= Time.deltaTime;
         }
 
         
 
     }
  
     public void Knockback(Vector3 direction)
     {
         
         knockBackCounter = knockBackTime;
         anim.Play("Jump");
         audioSource.PlayOneShot(HurtSound, 50F);
         moveDirection = direction * knockBackForce;
         moveDirection.y = knockBackForce;
     }
 
  
 }
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

627 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Idle Animations, Player Walking 0 Answers

Having problems with animation and character controller velocity not matching 0 Answers

Stopping the Character Controller 0 Answers

How can I have a CharacterController's height make it to where the feet are correctly on the ground? 0 Answers

Stop Root Motion if out of boundaries? Simple Wall Climbing System 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