|
Quick jump code issue
#312582
02/25/10 16:11
02/25/10 16:11
|
Joined: Oct 2009
Posts: 60
Tman
OP
Junior Member
|
OP
Junior Member
Joined: Oct 2009
Posts: 60
|
I have a jump code and it works great for when the player is not moving but when I am running and then jump he seems to glide and not land on his feet, anyone has ideas? Here is a portion of my code.
// adjust entity to the ground height, using a downwards trace
if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_PASSABLE|IGNORE_ME) > 0)
dist_down= my.z + vFeet.z - hit.z; // always place player's feet on the ground
else
dist_down = 0;
if((dist_down > 0))
{
dist_down = clamp(dist_down,100,accelerate(speed_down,-nc_gravity * time_step,0.1));
}
else
{
//do the speed down to equal 0 so that he snaps to the ground
speed_down = 0;
if((dist_down + speed_down)> 0)
{
speed_down = - dist_down - 0;
}
if(key_space == 1)
{
jump_target = jump_height * time_step;
}
}
if(jump_target > 0)
{
speed_down = (sqrt((jump_target)* nc_gravity))*time_step;
jump_target -= speed_down ;
}
This is the jump portion any help is appreciated.
|
|
|
Re: Quick jump code issue
[Re: Superku]
#312672
02/25/10 20:45
02/25/10 20:45
|
Joined: Jan 2004
Posts: 439
Gamesaint762
Senior Member
|
Senior Member
Joined: Jan 2004
Posts: 439
|
Im working with Tman so here is the screenshot for the level hes talking about. Thanks! The player runs by pressing forward key. Press space bar and he does jump animation, however when he returns to the ground instead of doing the landing animation and then going into a run he just stops and then glides across terrain. Its as if he never gets back down to the ground.
Last edited by Gamesaint762; 02/25/10 21:35.
|
|
|
Re: Quick jump code issue
[Re: Tman]
#312685
02/25/10 22:38
02/25/10 22:38
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Ok. I've understood your problem as follows: You've made a terrain in an extern program (Maya), that is not an A7-terrain but an A7-model. You want it to behave like a terrain. AFAIK you only have to set(terrain,POLYGON). When "polygon" is set, the model still needs a bounding box. When c_trace/c_move hits the bounding box, then (!) the engine will check the polygonal shape and if there is contact or not. So it's fine if the bbox is a little bit bigger than the model itself. Here is a code that I've written some days ago for someone else, so I know that it works (you may test the current model/ situation with it): action player_walk() { var anim_percent = 0; var grounddist, key_space_released = 0; VECTOR speed,temp; vec_set(speed,nullvector); wait(1); vec_set(temp,vector(-15,-15,-20)); // die bounding box setzen vec_scale(temp,my.scale_x); //falls der spieler im level eine andere größe als 1 hat vec_set(my.min_x,temp);
vec_set(temp,vector(15,15,20)); // die bounding box setzen vec_scale(temp,my.scale_x); //falls der spieler im level eine andere größe als 1 hat vec_set(my.max_x,temp); my.z += 232;
while(1) { if(!key_space) { key_space_released = 1; } // endlose Sprungwiederholung bei gedrückter Taste verhindern if(key_a || key_d) { my.pan = 180*key_a; anim_percent += 8*time_step; ent_animate(me, "run", anim_percent, ANM_CYCLE); } else { anim_percent += 4*time_step; ent_animate(me, "stand", anim_percent, ANM_CYCLE); }
speed.x += (45*(key_d-key_a)-speed.x)/3*time_step; // sanftes beschleunigen grounddist = c_trace(my.x,vector(my.x,my.y,my.z-150),IGNORE_ME | USE_BOX); grounddist = clamp(grounddist+150*(!trace_hit),-5,150);
if(grounddist < 10 && speed.z <= 0) {
my.z -= grounddist-5; speed.z = 0; if(key_space && key_space_released) { speed.z = 50; } } else { speed.z += maxv((-60-speed.z)/5,-7)*time_step; }
c_move(my,nullvector, vector(speed.x*time_step,0,speed.z*time_step),GLIDE); //Cameraposition camera.x = 100+my.x; camera.y = -2500; camera.z = 400+my.z; camera.pan = 90; camera.tilt = -5; wait(1); } }
Next, try using the polygon flag in trace_mode (I've never used it before, pls check the manual). Then try it with a normal A7-terrain from MED. EDIT: I'm not sure what your code should do:
// adjust entity to the ground height, using a downwards trace
if(c_trace(my.x,vector(my.x,my.y,my.z-5000),IGNORE_PASSABLE|IGNORE_ME) > 0)
dist_down= my.z + vFeet.z - hit.z; // always place player's feet on the ground
else
[b]dist_down = 0;[/b]
if((dist_down > 0))
{
dist_down = [b]clamp(dist_down,100,accelerate(speed_down,-nc_gravity * time_step,0.1));[/b]
}
The limits in clamp are -,+ not +,- if I read your code right. Then why do you set down_dist = 0; ? (I did not spend much time on understanding it, though) Have you tested the code with block geometry? Then, try if(down_dist > 5) { ... }.
Last edited by Superku; 02/25/10 22:43.
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
|