This is what I have so far. Now I want to make him jump, but if I do it the same way I did the movement, how do I make him fall back to the ground? I saw someone talking about raycasting or something, can someone explain me how I could achieve to make him jump?
I know Unity pretty well, but I’m just completely horrible at coding, and I dont understand all of the examples in the scripting reference
I tried doing exactly what you described, but that wont work because my character wont fall down to the ground again. He just keeps going up X amount of units and stays there.
you can keep jumping because the is no check for grounding.
If you have a Character controller on your mesh you can check for grounding.
So as long as player not grounded he shouldent be able to push jump.
And if not grounded move down.
so would be something like.
var JumpSpeed : int = 10;
var gravity : int : 10;
var controller = GetComponent(CharacterController);
if (controller.isGrounded) {
if (Input.GetKeyDown("jump")) {
transform.translate.y += jumpSpeed;
}
}
// Apply gravity
transform.translate.y -= gravity * Time.deltaTime;
But this will also have it move tru the ground as the is no stopping translate.
So the is another way, using move and simpelmove.
And check move. Here the is also a script about all this :). That why i said so in last post.
But that script work perfectly if you are in a 3D world.