0 registered members (),
803
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Jumping troubles
#205303
05/05/08 18:21
05/05/08 18:21
|
Joined: Apr 2007
Posts: 249 Louisana, USA
Ilidrake
OP
Member
|
OP
Member
Joined: Apr 2007
Posts: 249
Louisana, USA
|
I've looked everywhere, KHMovement, FPS guides, the manual, these forums and I can't find a solution to my jumping problem. The code works, just not smoothly. I want a nice steady arc upward and downward at the same speed like the old Mario games jumping. The code below works it's just sometimes the player will hang in the air and "fly" before they come back down. Can anyone help me out and tell me what I'm doing wrong?
action players_vehicle { player = me; my.falling = 0; my.shadow = on; while (lives > 0) { vec_set(temp,my.x); temp.z -= 1000; my.fall_distance = c_trace(my.x, temp, IGNORE_ME|IGNORE_PASSABLE|IGNORE_SPRITES|ACTIVATE_SONAR|SCAN_TEXTURE|USE_BOX); //check if jumping if (my.jumping != 0) { if (my.jump_height > 256 && my.jumping == 1) { my.jumping = 0; move_vec.z = 0; my.jump_height = 0; } else { if (move_vec.z > 1*time) { move_vec.z -= .3*time; my.jump_height += move_vec.z; } else { move_vec.z = 1*time; my.jump_height += move_vec.z; } } } //check if falling if (my.fall_distance > 500 && sign(my.fall_distance) != -1 && my.jumping == 0) { my.falling = 1; } else { if (my.fall_distance < 500 && my.falling == 0 && my.jumping == 0) { move_vec.z = -my.fall_distance*time; } } if (my.fall_distance > 256) { my.falling = 1; if (move_vec.z > -20*time) { move_vec.z -= .3*time; } } if (key_j) { if (my.jumping == 0 && my.falling == 0 && my.fall_distance < 1) { my.jumping = 1; move_vec.z = 45 * time; } } move_vec[0] = (key_cur + key_cul)*25 *time; if (key_cur == 1){my.pan = 0;} if (key_cul == 1){my.pan = 180;} c_move(me,move_vec,nullvector,IGNORE_PASSABLE|GLIDE); player_animate(); handle_camera(); wait(1); } }
function player_animate() { my.skill1 += 3*time_step; if (my.skill1 > 100) {my.skill1 -= 100;} if (my.falling == 1) { if (my.fall_distance < 0) { move_vec.z = -my.fall_distance*time; } else { my.falling = 0; } } if (move_vec[0] == 0 && move_vec[1] == 0) { ent_animate(me,"idle",my.skill1,ANM_CYCLE); } else { ent_animate(me,"roll",my.skill1,ANM_CYCLE); } }
function handle_camera() { camera.x = my.x; camera.y = my.y - 1500; camera.z = my.z + 100; camera.pan = 90; }
|
|
|
Re: Jumping troubles
[Re: Ilidrake]
#205495
05/06/08 20:14
05/06/08 20:14
|
Joined: Oct 2007
Posts: 116
sydan
Member
|
Member
Joined: Oct 2007
Posts: 116
|
Okay my way is kinda crazy simple and basically works like real life. I don't know if it will help. Youre player has 3 alocated skils for absolute movement so in c_move you put c_move(me,vector(my.speedx,0,0), vector(my.absx, my.absy, my.absz), GLIDE) where absx absy and absz are the absolute (i.e. aligned to room axis) movements Somewhere you do a trace that checks to see if the player is NOT on the floor if so you increase the my.absz by your gravity amount. If the player is on the floor then the increasing the my.absz stops so they nolonger accelerate and my.absz = 0 so they stop falling. For jumping all you do is check that the player is on the ground then if it is, when a key is pressed my.absz = 20 (or some suitable value) this cause the player to jump up in the air and then the gravity kicks in dropping them back to the ground smoothly. um yeah I rushed that so if it didn't make sense here's my current game code showing the trace that handles the whole thing.
// gravity trace
vec_set(temp.x, my.x); // copies entity x/y/z/ to the temp vector
temp.z -= 99999; // we set the temp vector ? quants straight down, below the entity
result = c_trace(my.x,temp.x,IGNORE_ME|IGNORE_PASSABLE|USE_BOX|USE_POLYGON|IGNORE_PUSH); // do a trace and make result = to the found value
if(result > 0) // chech to see if an obstacle was hit, if so start the falling action
{
my.absz -= my.grav_acc*time; // fall
my.res = 0.2;
}
if((result < 60) && (result > 0)) // check to see if the entity is on the ground, if so stop falling
{
my.absz = 0;
my.res = 0.5;
}
if((result < 40) && (result >0)) // check if entity is bellow ground (fallen through) if so rise up
{
my.absz += 40*time;
my.res = 0.5;
}
if(result == 0) // if nothing is bellow the entity i.e. outside room area, then gravity stops
{
my.absz -= my.grav_acc*time;
}
If you need help with my rushed message I will probably be around some other time to reexplain it I have to go so I hope that helped. Sydan
For some reason, my ambition always seems to beat my ability.
|
|
|
Re: Jumping troubles
[Re: Ilidrake]
#205623
05/07/08 16:47
05/07/08 16:47
|
Joined: Oct 2007
Posts: 116
sydan
Member
|
Member
Joined: Oct 2007
Posts: 116
|
No problem in all honesty I started doing what you did and then I made a game with that, it didn't work I gave up forgot your method made a new game and worked this one out so yeah. Did you try to use the fps tutorial from acknex?
For some reason, my ambition always seems to beat my ability.
|
|
|
|