- Home /
Forward jumping
Good afternoon,
I have tried several scrips and codes found on the forum/Google and in here. But none of the found codes seem to work for me.
I have a character controller + rigid-body attached, and a movement script. In my void Update i check to see if the player pressed the space, then i set the flag for my animator to play the jump animation, and i add force to the rigid-body.
But the player just stops his running/sneaking/walking animation and movement, and than jumps straight upward (and stops slightly above ground again). Then he continues his movement (stepping down to the ground first).
if (Input.GetKeyDown (KeyCode.Space) && move > 0.1) {
anim.SetTrigger (jumpHash);
rigidbody.AddForce(Vector3.forward * jumpForce);
}
But it seems to have no effect... any suggestions ?
I played around with a new layer (jumping on his own) so i could combine 2 animations on different layers. which seems to work, but now he jumps like his leg is numb. Any good advice ?
Answer by Qasem2014 · Dec 31, 2014 at 11:00 AM
check this for your jumping code :
GetComponent.<Rigidbody>().velocity = transform.TransformDirection(Vector3(0 , 20 , 0));
Vector3(0 , 20 , 0) mean add force to Y direction . maybe you need take a higher or lower number then 20 for your object .
That code, set my character flying upwards indefinitely, when i'm standing still. When i press jump, nothing happens.
do you change the number "20" ?
it should work !!!! :-?
OH
there is a very good tutorial :
https://www.youtube.com/watch?v=s7EIp-OqVyk
jumping whit animation when character is running using animator via scripts :)