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. Dismiss Notice

Character Controller smooth jump

Discussion in 'Scripting' started by bbQsauce, Sep 1, 2014.

  1. bbQsauce

    bbQsauce

    Joined:
    Jun 29, 2014
    Posts:
    53
    Hi everyone, i'm currently trying to make a character controller for a mobile game i'm developing, but i'm stuck figuring out how to make a smooth jump instead of the linear i have now, i need a smooth jump, just like the basic character controller from unity does.

    This is what i have:


    I have a button, to make the controller jump.

    This is the script snipped out

    Code (CSharp):
    1.  
    2.  
    3.  
    4.     private CharacterController player;
    5.  
    6.     public float jumpSpeed=5f;
    7.  
    8.     public float gravity=8f;
    9.  
    10.  
    11.     void Start()
    12.         {
    13.         player = GetComponent<CharacterController> ();
    14.         }
    15.      
    16.     void Update()
    17.     {          
    18.             if (jumpButton.IsPressed())  
    19.             {
    20.                 if(player.isGrounded)
    21.                 player.Move(new Vector3(0.0f,jumpSpeed*Time.deltaTime,0.0f));              
    22.             }        
    23.        }
    24.  
    25.        if(!player.isGrounded)
    26.             player.Move(new Vector3(0.0f,gravity*Time.deltaTime,0.0f));
    27.     }
    28.    
    How do you make a smooth, accelerated jump?

    Thanks in advance
     
  2. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Why you wouldn't use Rigidbody with UseGravity?
     
  3. bbQsauce

    bbQsauce

    Joined:
    Jun 29, 2014
    Posts:
    53
    I tried to use a rigidbody with gravity as well, but it goes through terrain.. and if i put a capsule collider it is just glitchy with CharacterController.Move .... i can't get it to work.. do you know how to do that?