Not sure where to put this but...
Ive been looking for a decent jump script but, like many, not found one that really looks right so I decided to make a script that deals only with gravity and then make a player jump with just his initial velocity which is then acted upon by gravity.
It works well enough and was hoping others can test to see how it works for them as there are still problems with it such as when gravity kicks in it can suck the player to the ground. Also the initial velocity of jumping seems a bit slow for me and the character sinks into the ground a bit and then pops back up when at rest.
Anyway here it is, based on Lancaster's KH movement code
//place variables in your variable list
var gravity = -0.1; //higher the value, the stronger gravity works
var time_count = 0;
//place code below in player action code
move_result = c_trace(vector(my.x,my.y,my.z - my.z_offset), vector(my.x,my.y,my.z - 4000),use_aabb | ignore_passable | glide); //find distance of ground to player
IF (move_result < 1) //am I in ground? push me back up
{
my.move_z = -1 * move_result;
time_count = 0;
IF (key_space == 0 && space_press == 1 ) { space_press = 0; }
IF (key_space == 1 && space_press == 0 )
{
space_press = 1;
my.velocity_z = 3 * time; //higher the velocity the bigger the jump
}
}
IF (key_space == 0 && space_press == 0 ) {my.velocity_z = 0;}
time_count += time; //store amount of time whilst in air
my.move_z =(my.velocity_z * time_count) + ((gravity * pow(time_count,2))/2); //gravity equation
my.move_x = current_speed * time; //horizontal movement
c_move(my,my.move_x,nullvector, use_aabb | ignore_passable | glide);
Thats it, let me know how it works for you.
*edit* changed velocity to a lower value
Last edited by TigerTao; 02/16/07 21:35.