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 Descend · Dec 03, 2012 at 04:21 AM · animation

Character goes into unwanted state.

hello, fellow members. I appreciate anyone who can help me with this problem I'm having. My problem is that my Land animation keeps running after my character jumps and keeps going into a landing state after jump state then from a landing state into a falling state. My character go into a landing state if it isn't grounded.I have the code set up where if it is not grounded it shouldn't play that animation.I don't know what the problem is. Please if anyone can help, I thank you.

using UnityEngine; using System.Collections;

public class ThirdPersonAnimator : MonoBehaviour { // List of states. public enum Direction { Stationary, Forward, Backward, Left, Right, Leftforward, Rightforward, LeftBackward, RightBackward } public enum CharacterState { Idle, Walking, Running, WalkingBackwards, StrafingLeft, StrafingRight, Jumping, Falling, Landing, Climbing, Sliding, Using, Dead, ActionLocked } public static ThirdPersonAnimator Instance ; //Record last state private CharacterState lastState ; private Transform Root ; private Vector3 initialPosition = Vector3.zero ; private Quaternion initialRotation = Quaternion.identity ; private GameObject ragdoll ; public Direction MoveDirection { get; set; } public CharacterState State { get; set; } public bool IsDead { get ; set ; } public bool isRunning = false ; // Use this for initialization void Awake () { Instance = this ; // We are looking for our skeleton root node // skeleton root = PlayerArmature Root = transform.FindChild("PlayerArmature/Root") as Transform ; initialPosition = transform.position ; initialRotation = transform.rotation ; } // Update is called once per frame void Update () { // Begin processing animator for run fuction. //if (isRunning == true) //{ //Debug.Log ("isRunning is on"); //State = CharacterState.Running ; if (State == CharacterState.Jumping) { //State = lastState ; ThirdPersonController.Instance.isRunning = false ; //DetermineCurrentState () ; //ProcessCurrentState () ; } DetermineCurrentState () ; ProcessCurrentState () ; //} //if (isRunning == false) //{ //Debug.Log ("isRunning is off"); //DetermineCurrentState () ; //ProcessCurrentState () ; //} Debug.Log("Current Character State: " + State.ToString()) ; // End of processing animator for run function. } public void DetermineCurrentMoveDirection () { var forward = false ; var backward = false ; var left = false ; var right = false ; if (ThirdPersonMotor.Instance.MoveVector.z > 0) { forward = true ; } if (ThirdPersonMotor.Instance.MoveVector.z < 0) { backward = true ; } if (ThirdPersonMotor.Instance.MoveVector.x > 0) { right = true ; } if (ThirdPersonMotor.Instance.MoveVector.x < 0) { left = true ; } if (forward) { if (left) { MoveDirection = Direction.Leftforward ; } else if (right) { MoveDirection = Direction.Rightforward ; } else { MoveDirection = Direction.Forward ; } } else if (backward) { if (left) { MoveDirection = Direction.LeftBackward ; } else if (right) { MoveDirection = Direction.RightBackward ; } else { MoveDirection = Direction.Backward ; } } else if (left) { MoveDirection = Direction.Left ; } else if (right) { MoveDirection = Direction.Right ; } else { MoveDirection = Direction.Stationary ; } } void DetermineCurrentState () { if (State == CharacterState.Dead) { return ; } if (!ThirdPersonController.CharacterController.isGrounded) { if (State != CharacterState.Falling && State != CharacterState.Jumping && State != CharacterState.Landing) { //We Should be falling Fall() ; } } if (State != CharacterState.Falling && State != CharacterState.Jumping && State != CharacterState.Landing && State != CharacterState.Using && State != CharacterState.Climbing && State != CharacterState.Sliding) { switch (MoveDirection) { case Direction.Stationary: State = CharacterState.Idle ; break ; case Direction.Forward: if (isRunning == true ) { State = CharacterState.Running ; } else { State = CharacterState.Walking ; } break ; case Direction.Backward: State = CharacterState.WalkingBackwards ; break ; case Direction.Left: State = CharacterState.StrafingLeft ; break ; case Direction.Right: State = CharacterState.StrafingRight ; break ; case Direction.Rightforward: State = CharacterState.Walking ; break ; case Direction.Leftforward: State = CharacterState.Walking ; break ; case Direction.RightBackward: State = CharacterState.WalkingBackwards ; break ; case Direction.LeftBackward: State = CharacterState.WalkingBackwards ; break ; } } } void ProcessCurrentState () { switch (State) { case CharacterState.Idle: Idle() ; break ; case CharacterState.Walking: Walking() ; break ; case CharacterState.Running: Running() ; break ; case CharacterState.WalkingBackwards: WalkBackwards() ; break ; case CharacterState.StrafingLeft: StrafingLeft() ; break ; case CharacterState.StrafingRight: StrafingRight() ; break ; case CharacterState.Jumping: Jumping() ; break ; case CharacterState.Falling: Falling() ; break ; case CharacterState.Landing: Landing() ; break ; case CharacterState.Climbing: break ; case CharacterState.Sliding: Sliding() ; break ; case CharacterState.Using: Using(); break ; case CharacterState.Dead: Dead() ; break ; case CharacterState.ActionLocked: break ; } } #region Character State Methods void Idle () { animation.CrossFade("M_Idle") ; } void Running() { animation.CrossFade("M_Run") ; } void Walking() { animation.CrossFade("M_Walk") ; } void WalkBackwards() { animation.CrossFade("M_WalkBackwards") ; } void StrafingLeft() { animation.CrossFade("M_StrafingLeft") ; } void StrafingRight() { animation.CrossFade("M_StrafingRight") ; } void Using() { if (!animation.isPlaying) { State = CharacterState.Idle ; animation.CrossFade("Idle"); } } void Jumping() { if ((!animation.isPlaying && ThirdPersonController.CharacterController.isGrounded) || ThirdPersonController.CharacterController.isGrounded) { if (lastState == CharacterState.Walking || lastState == CharacterState.Running ) { animation.CrossFade("M_WalkLand") ; } else { animation.CrossFade("M_JumpLand") ; } State = CharacterState.Landing ; } else if (!animation.IsPlaying("M_Jump")) { State = CharacterState.Falling ; animation.CrossFade("M_Falling") ; ThirdPersonMotor.Instance.IsFalling = true ; } else { State = CharacterState.Jumping ; //Help determine if we fall to far. } } void Falling() { if (ThirdPersonController.CharacterController.isGrounded) { if (lastState == CharacterState.Walking || lastState == CharacterState.Running) { animation.CrossFade("M_WalkLand") ; } else { animation.CrossFade("M_JumpLand") ; } State = CharacterState.Landing ; } } void Landing() { //animation.Stop("M_JumpLand") ; if (lastState == CharacterState.Walking) { if (!animation.IsPlaying("M_WalkLand")) { State = CharacterState.Walking ; animation.Play("M_Walk") ; } } else if (lastState == CharacterState.Running) { if (!animation.IsPlaying("M_WalkLand")) { State = CharacterState.Running ; animation.Play("M_Run") ; } } else { if (!animation.IsPlaying("M_JumpLand")) { State = CharacterState.Idle ; animation.Play("M_Idle") ; } } ThirdPersonMotor.Instance.IsFalling = false ; } void Sliding() { if (!ThirdPersonMotor.Instance.IsSliding) { State = CharacterState.Idle ; animation.CrossFade("M_Idle") ; } } void Dead() { State = CharacterState.Dead ; } #endregion #region Start Action Method / Begin processing animator for run fuction. public void Run() { if (isRunning == true) { Debug.Log ("isRunning is on"); State = CharacterState.Running ; } if (isRunning == false) { Debug.Log ("isRunning is off"); State = CharacterState.Walking ; } } // End of processing animator for run function. / public void Use() { State = CharacterState.Using ; animation.CrossFade("M_Use") ; } public void Jump() { if (!ThirdPersonController.CharacterController.isGrounded || IsDead || State == CharacterState.Jumping) { return ; } lastState = State ; State = CharacterState.Jumping ; animation.CrossFade("M_Jump") ; } public void Fall() { if (ThirdPersonMotor.Instance.VerticalVelocity > -5 || IsDead) { return ; } lastState = State ; State = CharacterState.Falling ; // If we are too high do something ThirdPersonMotor.Instance.IsFalling = true ; animation.CrossFade("M_Falling") ; } public void Slide() { State = CharacterState.Sliding ; animation.CrossFade("M_Falling") ; } public void Die() { //Intialize everything we need to die IsDead = true ; SetupRagdoll() ; Dead() ; } public void Reset() { IsDead = false ; transform.position = initialPosition ; transform.rotation = initialRotation ; State = CharacterState.Idle ; animation.Play ("M_Idle"); ClearRagdoll() ; }

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Animation Problem 2 Answers

Unity not importing blender animations at all 7 Answers

Quaternion to matrix conv. error 0 Answers

Can I make animations snap to a frame? 1 Answer

Input.GetAxis Animation Problem 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