|
Re: Jumping troubles
[Re: DJBMASTER]
#205685
05/07/08 23:32
05/07/08 23:32
|
Joined: Apr 2007
Posts: 249 Louisana, USA
Ilidrake
OP
Member
|
OP
Member
Joined: Apr 2007
Posts: 249
Louisana, USA
|
Sure. Here it is slightly modified and noted so you know whats what.
var move_vec[3] = 0,0,0; //movement vectors var jumping = 0; var lives = 3;
action players_vehicle { player = me; my.shadow = on; my.grav_acc = 3; //acceleration for gravity my.res = 0; //not sure what this is for. left it in for the heck of it while (lives > 0) { 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 { move_vec.z -= my.grav_acc*time; // fall my.res = -0; } if((result < 10) && (result > 0)) // check to see if the entity is on the ground, if so stop falling. This is the number to change if your entity floats on above the ground { move_vec.z = 0; my.res = -0; } if((result < 1) && (result >0)) // check if entity is below ground (fallen through) if so rise up. Also a number to play with if your entity floats above the ground or double jumps. Should never be larger than the above number { move_vec.z += 10*time; my.res = -0; } if (move_vec.z == 0) //so player can't double jump. Jump is over so reset to allow jumping again { jumping = 0; } if (key_j && jumping != 1) //if j key and player isnt in a jump let'em jump { jumping = 1; //keep'em from double jumping move_vec.z += 95*time; // jump } move_vec = (key_cur + key_cul)*30 *time; //how far to move on the x axis if (key_cur == 1){my.pan = 0;} //change pan depending on which key is pressed if (key_cul == 1){my.pan = 180;} c_move(me, move_vec, nullvector,IGNORE_PASSABLE|GLIDE); //actual movement player_animate(); //go handle animations handle_camera(); //go handle camera wait(1); } }
Hope this helps ya out.
|
|
|
Re: Jumping troubles
[Re: DJBMASTER]
#205790
05/08/08 20:44
05/08/08 20:44
|
Joined: Oct 2007
Posts: 116
sydan
Member
|
Member
Joined: Oct 2007
Posts: 116
|
Grimbers juming code doesn't work, but don''t let that put you off his tutorials thpeir still brilliant. I suggest you either make your own or use mine. See above.
For some reason, my ambition always seems to beat my ability.
|
|
|
Re: Jumping troubles
[Re: Ilidrake]
#205799
05/08/08 21:35
05/08/08 21:35
|
Joined: Nov 2007
Posts: 1,143 United Kingdom
DJBMASTER
Serious User
|
Serious User
Joined: Nov 2007
Posts: 1,143
United Kingdom
|
Ok this is my code... Could you help me implement realistic jumping?....
var move_vec[3] = 0,0,0;
var walk_speed = 16;
var falling =0;
var fall_distance = 0;
action player_move
{
player = me;
camera.genius=player;
wait(1);
while (player !=NULL)
{
move_vec[0] = (key_w - key_s)*walk_speed *time;
move_vec[1] = (key_a - key_d) *walk_speed *time;
vec_set(temp,my.x);
temp.z-=4000;
fall_distance = c_trace(my.x,temp,ignore_me+ignore_sprites+USE_BOX);
If (fall_distance >64 && sign(fall_distance) != -1)
{
falling = 1;
}
else
{
if ( fall_distance < 64 && falling == 0 )
{
move_vec.z = -fall_distance*time;
}
}
If (fall_distance >32)
{
falling = 1; // now I'm falling
if (move_vec.z > -20*time)
{
move_vec.z -= .5*time;
}
falling = 0;
}
if (fall_distance < 0)
{
move_vec.z = -fall_distance*time;
}
my.pan -= mouse_force.x*walk_speed*time_step;
camera.tilt += mouse_force.y*walk_speed*time_step;
camera.pan = my.pan;
camera.tilt = clamp(camera.tilt,-70,70);
c_move(me,move_vec,nullvector,glide+USE_BOX);
vec_set (Camera.x,player.x);
camera.z += 27;
wait(1);
}
} Hope some1 can help me implement jumping...thanks a lot... DJB
Last edited by DJBMASTER; 05/08/08 21:38.
|
|
|
Re: Jumping troubles
[Re: sydan]
#205800
05/08/08 21:36
05/08/08 21:36
|
Joined: Apr 2007
Posts: 249 Louisana, USA
Ilidrake
OP
Member
|
OP
Member
Joined: Apr 2007
Posts: 249
Louisana, USA
|
I never had any trouble with Grimbers jump code. I've heard a lot of ppl say they have but its always worked for me. It could be smoother but it does work.
One thing to remember about Grimbers code is some of the code for falling is in the animation functions as well so you need to check that segment as well.
Last edited by Ilidrake; 05/08/08 21:38.
|
|
|
Re: Jumping troubles
[Re: DJBMASTER]
#205805
05/08/08 22:06
05/08/08 22:06
|
Joined: Apr 2007
Posts: 249 Louisana, USA
Ilidrake
OP
Member
|
OP
Member
Joined: Apr 2007
Posts: 249
Louisana, USA
|
Ya. I'm looking over it. Gimme a little time to test it. In the meantime here's the code from Grimbar's tuts that works for me. Like I said, it's not mine but it does work.
//player movement functions var move_vec[3] = 0,0,0; var idle_percent = 0; var walk_percent = 0; var temptilt = 0; var distance_traced; var land_percent = 60; var camstat = 1; var max_dist = 2; var cam_point = 0; var head_height = 20;
//uses: battery, armor, health, ammo, battery_max, armor_max, health_max, ammo_max, falling, fall_distance, jumping, jump_height action player_move { player = me; my.shadow = on; my.falling = 0; camera.genius = me; wait(1); shift_sense = 2; run_weapons(); while (my.health > 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 >32 && my.jumping == 1)||(my.jumping == 2 && my.jump_height > 64)) { my.jumping = 0; move_vec.z = 0; my.jump_height = 0; } else { if (move_vec.z > 1*time) { move_vec.z -= .5*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 < 64 && my.falling == 0 && my.jumping == 0) { move_vec.z = -my.fall_distance*time; } } if (my.fall_distance > 32) { my.falling = 1; if (move_vec.z > -20*time) { move_vec.z -= .5*time; } } if (key_j) { if (my.jumping == 0 && my.falling == 0 && my.fall_distance < 1) { my.jumping = 1 + key_shift; move_vec.z = 20*time; } } move_vec[0] = (key_force.y)*8*time; move_vec[1] = (-key_force.x)*8*time; player.pan -= (mouse_force.x)*6*time; c_move(me,move_vec,nullvector,IGNORE_PASSABLE|GLIDE); player_animate(); handle_camera(); //update_camera(); wait(1); } }
//uses: falling, fall_distance function player_animate() { if (my.falling == 1) { if (my.fall_distance > 32) { ent_animate(me, "jump", 60, anm_add); } else { if (int(land_percent) != 0) { land_percent = (land_percent +8*time)%100; ent_animate(me, "jump", land_percent, anm_add); if (my.fall_distance < 0) { move_vec.z = -my.fall_distance*time; } } else { my.falling = 0; land_percent = 60; } } } if (move_vec[0] == 0 && move_vec[1] == 0) { idle_percent = (idle_percent +5*time)%100; ent_animate(me,"idle",idle_percent,ANM_CYCLE); } else { walk_percent = (walk_percent + sign(move_vec[0])*5*time)%100; ent_animate(me,"walk",walk_percent,ANM_CYCLE); } wait(1); }
function handle_camera() { vec_set(camera.x, player.x); camera.z += 30; camera.pan = player.pan; temptilt +=(mouse_force.y)*6*time; if (key_home){temptilt=0;} if(temptilt > 35) { temptilt = 35; } else { if(temptilt < -75) { temptilt = -75; } } camera.tilt = 0 + temptilt; wait(1); }
function update_camera() { vec_set(camera.x, vector(my.x, my.y, my.z+head_height)); if (key_force.y) { if (camstat == 1) { cam_point+= 1; if (cam_point>max_dist) { camstat = 0; } } else { cam_point -= 1; if (cam_point <(-1*max_dist)) { camstat = 1; } } camera.z+=cam_point; } else { cam_point = 0; } }
|
|
|
|