3D Game-Making a character jump

I’ve tried various ways. I can make my character go up, just not come back down. Also, I want that acceleration effect when jump, so it looks lees like walking upward. The only way I can think of doing it would be too primitive for Unity, which is adding collision for each object, and using some sort of time or jump height for coming back down. ANy help appreciated, or better yet, some snippet of javascript jump code. I would prefer not to use the axis, and just jump from the “ground” my character is on. Here’s some code snipped:

var controller : CharacterController = GetComponent(CharacterController);
		if (controller.isGrounded){
			//if(Input.GetKey(KeyCode.Space)){
				//transform.Translate(Vector3.up * jumpSpeed * Time.deltaTime); 
				//transform.position += transform.up * jumpSpeed * Time.deltaTime;
			//}
			if (Input.GetKeyDown ("space")){
				transform.Translate(Vector3.up * jumpSpeed * Time.deltaTime, Space.World);
         } 
		}

Hi!

check this video it may help you:

Using Zodiarc’s coment:


    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded){
    	if (Input.GetKeyDown ("space")){
    		rigidbody.AddForce (Vector3.up);
    	} 
    }

For this to work, you need to have a rigidbody(3d) attached to your character.

add this to the code:

var customGravity : float = 10;
var isGrounded : boolean = true;
    
function Update()
{
    if(isGrounded == false)
    {
        transform.position -= Vector3.up * customGravity * Time.deltaTime;
    }

    if(isGrounded)
    {
        //do nothing
    }
}

function OnCollisionStay ()
{
	isGrounded = true;
}

function OnCollisionExit()
{
	isGrounded = false;
}

what this basically does is that if you are not grounded (on the floor) you will apply an opposite force on the y axis which is gravity; and when you are on the floor it will do nothing. in small words you are just emulating gravity. I have not tried this script so i do not know if it will work. you may have a bug that gravity won`t apply when you are touching a wall or anything else that is vertical.