Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

problem with jump animation

Discussion in 'Editor & General Support' started by cedart, Jul 15, 2014.

  1. cedart

    cedart

    Joined:
    Jul 10, 2014
    Posts:
    17
    Hello,

    I continue to learn unity, and I advance :)

    But i'm blocked with the jump. I have a jump up animation, et I want to jump more heigher, and during the sprint.
    But it doesn't work :/

    That's the "game" : www.cedricletort.com/unity

    And my javascript :


    Code (JavaScript):
    1. #pragma strict
    2.  
    3. internal var animator:Animator;
    4. var v:float;
    5. var h:float;
    6. var sprint:float;
    7.  
    8. function Start () {
    9.     animator = GetComponent(Animator);
    10. }
    11.  
    12. function Update () {
    13.     v = Input.GetAxis("Vertical");
    14.     h = Input.GetAxis("Horizontal");
    15.     /*Sprinting();*/
    16.    
    17.     //rotation du perso : le produit est la vitesse de rotation
    18.     transform.Rotate(Vector3(0,Input.GetAxis("Horizontal") * 1.5,0));
    19.    
    20.     //Saut
    21.     if(Input.GetButtonDown("Jump")) {
    22.         var secondsLeft = 0.5;
    23.         while(secondsLeft > 0)
    24.         {
    25.             secondsLeft -= Time.deltaTime;
    26.             rigidbody.AddForce(new Vector3(0,10,0), ForceMode.Acceleration);
    27.            
    28.             animator.SetBool("Jump", true);
    29.         }
    30.        
    31.     }
    32.     else{
    33.         animator.SetBool("Jump", false);
    34.     }
    35. }
    36.  
    37. function FixedUpdate () {
    38.     animator.SetFloat("Walk", v);
    39.     /*animator.SetFloat("Sprint", sprint);*/
    40. }
    41.  
    42. /*function Sprinting () {
    43.     if(Input.GetKey(KeyCode.LeftShift)) {
    44.         sprint = 0.2;
    45.     }
    46.     else {
    47.         sprint = 0.0;
    48.     }
    49. }*/



    Can you help me ? :D

    Thanks ;)
     

    Attached Files:

  2. DexRobinson

    DexRobinson

    Joined:
    Jul 26, 2011
    Posts:
    594
    Increase the force you are jumping by. You can use your current speed and multiply it by your jump force. So when you are idle, you won't jump but if you are sprinting you will get a much higher jump.
     
  3. cedart

    cedart

    Joined:
    Jul 10, 2014
    Posts:
    17
    Thanks.

    But my jump isn't considered because of my jump animation. When I sprint and jump, my character stops then he jump on site.
    Movements are not considered because of the animation... Why ?