jumping with a character controller

i am making a simple 2d game and am using a character controller for my movement. i want the character to have a smooth jump but the script im using makes it instantly jump up and slowly fall back down. how can i make the jump smooth? this is the script im using:

var jump : int = 10;

function Update()
{
   if(Input.GetButtonDown("Jump") && controller.isGrounded)
      {
         transform.Translate(0, jump * Time.deltaTime, 0);
      }

}

See here http://docs.unity3d.com/Documentation/ScriptReference/CharacterController.Move.html the script has it all, movement and jump.

–

how do i do this without the movement parts?

–

3 Answers

3

Use .Move or .SimpleMove when using a Character Controller. Using the example code in Unity - Scripting API: CharacterController.Move you would do this to jump:

public float jumpSpeed = 8.0F;
public float gravity = 20.0F;
private Vector3 moveDirection = Vector3.zero;

void Update() {
    if (controller.isGrounded && Input.GetButton("Jump")) {
        moveDirection.y = jumpSpeed;
    }
    moveDirection.y -= gravity * Time.deltaTime;
    controller.Move(moveDirection * Time.deltaTime);
}

thank you so much you just saved my life O_o I have searched the intire internet for a smooth jump on a character controler but it is nowhere! thank you so much ;-;

–

It's really glitchy when you collide with an object.

–

How does that work? It’s setting the moveDirection’s Y instantly. How can it possibly be smooth?

CharacterController.Move interpolates automatically I believe, although this is without actually checking the docs so please correct me if I am wrong

–

The code that @mattssonon provided gets really glitchy when you collide with an object. How do I fix that?