How do i make my character jump?

Hello people, i have a question how do i make my character jump? I currently have this:

var speed = 3.0;

var rotateSpeed = 3.0;

var gravity = 2.0;

function Update ()

{ var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0); var forward = transform.TransformDirection(Vector3.forward); var curSpeed = speed * Input.GetAxis ("Vertical"); controller.SimpleMove(forward * curSpeed);

     if(controller.isGrounded)
         if(Input.GetButtonDown("Jump"))
         transform.position.y += gravity;

    }

@scriptRequireComponent(CharacterController)

Well this works... but it only gives a sudden jump. So when i press jump, my character is emiderly at the position. What i want is some kind of damping or something like that. Can you please help me?

Ah right I had just the same problem when I started a jump.

transform.position is the property that says where the vertical position is ( as you know). However if you want to jump that is a series of vertical positions over time based on horizontal and vertical momentum to construct the entire jump , with drag gravity applying it's even more fun.

You can do:

1: Recreate the entire series of event creating an arch like jump with acceleration decelleration, just get a quick physics brushup if needed and it's not that bad depending on your coding knowledge.

2: Use the inbuilt Move function that comes with Unity3D character controllers setting a change in the vertical direction. In JS you can even directly acces the Vector3 y value of the directionVector you create so making all changes per frame and doing 1 movement call is really easy.

function Update()
{
    if (someJumpEvent)
    {
        moveDirection.y += jumpHeight;
    }
    if (someJumpEventReachedMaxHeight && !notGrounded)
    {
        moveDirection.y -= applyDownwardSpeed;
    }

    //runDirection being a positive 1 or negative 1 value for absolute left or 
    //right really dirt cheap and not really good but just an example for
    //moveDirection editing
    if (someRunEvent)
    {
        moveDirection.x += RunSpeed * runDirection
    }

    myController.Move(moveDirection);
}

3: Use the physics engine and Addforce, kick the character in the pant with this and he should go flying. But do you really want kicking and punching for movement controls ? Probably not, so I would say no, but it IS possible, no idea what you are building so thought I'd add the option. You can check how here