Search Unity

Character gravity cuts in late.

Discussion in 'Animation' started by kanga, Nov 2, 2013.

  1. kanga

    kanga

    Joined:
    Mar 22, 2010
    Posts:
    225
    Hi
    My character has a Rigidbody and Character Controller attached. When the character walks off a building or incline it will continue to hold its position in the Y axis until the walk key is released. So when the model is moving forward it will not drop till its horizontal motion is zero. Anybody have something similar?

    Any advice gratefully accepted.
    Cheers
     
  2. kanga

    kanga

    Joined:
    Mar 22, 2010
    Posts:
    225
    So I put my character in a fresh scene and went through the setup. This time gravity was handled differently: the model would not fall unless it had forward motion (exactly the opposite of my main scene). I then opened the Unity locomotion starter kit , applied a character controller to the default character and it works perfectly. Here is the starter kit script.
    Code (csharp):
    1.  /// <summary>
    2. ///
    3. /// </summary>
    4.  
    5. using UnityEngine;
    6. using System;
    7. using System.Collections;
    8.  
    9. [RequireComponent(typeof(Animator))]  
    10.  
    11. //Name of class must be name of file as well
    12.  
    13. public class LocomotionPlayer : MonoBehaviour {
    14.  
    15.     protected Animator animator;
    16.  
    17.     private float speed = 0;
    18.     private float direction = 0;
    19.     private Locomotion locomotion = null;
    20.  
    21.     // Use this for initialization
    22.     void Start ()
    23.     {
    24.         animator = GetComponent<Animator>();
    25.         locomotion = new Locomotion(animator);
    26.     }
    27.    
    28.     void Update ()
    29.     {
    30.         if (animator  Camera.main)
    31.         {
    32.             JoystickToEvents.Do(transform,Camera.main.transform, ref speed, ref direction);
    33.             locomotion.Do(speed * 6, direction * 180);
    34.         }      
    35.     }
    36. }
    Here is the script from my main scene:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class IdleRunJumpAudio : MonoBehaviour {
    5.  
    6.  
    7.     protected Animator animator;
    8.     public float DirectionDampTime = .25f;
    9.     public bool ApplyGravity = true;
    10.     public AudioClip roar;
    11.     public AudioClip breath;
    12.     public AudioClip Attack;
    13.    
    14.     // Use this for initialization
    15.     void Start ()
    16.     {
    17.         animator = GetComponent<Animator>();
    18.     }
    19.        
    20.     // Update is called once per frame
    21.     void Update ()
    22.     {
    23.         float h = Input.GetAxis("Horizontal");              // setup h variable as our horizontal input axis
    24.         float v = Input.GetAxis("Vertical");                // setup v variables as our vertical input axis
    25.         animator.SetFloat("Speed", v);                          // set our animator's float parameter 'Speed' equal to the vertical input axis             
    26.         animator.SetFloat("Direction", h);                      // set our animator's float parameter 'Direction' equal to the horizontal input axis       
    27.                    
    28.         if (animator)
    29.         {
    30.             AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);         
    31.  
    32.             if (stateInfo.IsName("Base Layer.Run"))
    33.             {
    34.                 if (Input.GetButton("Fire1")) animator.SetBool("Jump", true);                
    35.             }
    36.             else
    37.             {
    38.                 animator.SetBool("Jump", false);                
    39.             }
    40.  
    41.             if(Input.GetKeyDown("r"))
    42.             {
    43.                 animator.SetBool("Roar", !animator.GetBool("Roar"));
    44.                 audio.PlayOneShot(roar);   
    45.             }
    46.             else
    47.             {
    48.                 animator.SetBool("Roar", false);
    49.             }
    50.             if(Input.GetKeyDown("t"))
    51.             {
    52.                 animator.SetBool("Slash", !animator.GetBool("Slash"));
    53.                 audio.PlayOneShot(Attack); 
    54.             }
    55.             else
    56.             {
    57.                 animator.SetBool("Slash", false);
    58.             }
    59.         }            
    60.     }
    61. }
    62.  
    Anyone see what I am missing?
    Cheers
     
    theANMATOR2b likes this.
  3. kanga

    kanga

    Joined:
    Mar 22, 2010
    Posts:
    225
    So playing about with the scene again this morning and everything is working as expected, but how????? Man voodoo is in the air :)
     
    theANMATOR2b likes this.
unityunity