|
|
Problem with Jump/Fall Code [GER/ENG]
#378577
07/24/11 19:11
07/24/11 19:11
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
Hi ihr.. Ich bin glaub grad zu doof zum coden.. könnt am Urlaub liegen.. Ich hab den nachfolgenden Jump/Fall Code geschrieben.. und es kommt ab und an vor, dass das Jumpobjekt (Spieler, Anderes) plötzlich im Boden steckt.. Völlig egal ob der Boden ein terrain, levelblock oder Model ist.. Hat wer grade so den Überblick woran des liegen könnte? Ps.: ich brauch die einzelnen abschnitte, weil später noch gleiten und fliegen dazukommt. ----------------------- Hi there.. i dunno why.. perhaps cause i´m in holidays.. but.. i´m t stupid to code.. i´ve written the following jump/fall code. And it happens sometimes, that when the player or another object lands, it stucks a bit in the ground. Can someone take a look at the code, please? Perhaps you can find the problem.. Ps.: I need the code to be split into many function, to seperate animations later, and to make adding gliding and flying easier.. Der Code: The Code:
void landing(ENTITY* obj)
{
obj.fallspeed = obj.fallspeedold;
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
while(obj.roofdist > (obj.objekthoehe/2))
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
c_move(obj, vector(0, 0, -(5*(bulleter/100))*time_step), nullvector, GLIDE | IGNORE_PASSABLE | USE_POLYGON);
wait(1);
}
//obj.z += obj.objekthoehe/2;
obj.in_jump = 0;
}
void fallgo(ENTITY* obj)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2)+4)
{
c_move(obj, vector(0, 0, -(obj.fallspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.fallspeed += (obj.gewicht/10.5)*time_step;
obj.fallspeed = clamp(obj.fallspeed, 0, 100);
}
else if(obj.roofdist <= (obj.objekthoehe/2)+4)
{
obj.in_jump = 4;
}
}
void fallstart(ENTITY* obj)
{
obj.jumpspeed = obj.jumpspeedold;
obj.fallspeedold = obj.fallspeed;
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2)+4)
{
c_move(obj, vector(0, 0, -(obj.fallspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.fallspeed += (obj.gewicht/10.5)*time_step;
obj.jumpkeytrigger = 1;
obj.in_jump = 3;
}
}
void jumpgo(ENTITY* obj)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2)+4 && obj.jumpspeed > 10)
{
c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.jumpspeed -= (obj.gewicht/10.5)*time_step;
}
else if(obj.roofdist < (obj.objekthoehe/2)+4)
{
obj.in_jump = 2;
}
else if(obj.jumpspeed <= 10)
{
obj.in_jump = 2;
}
else
{
obj.in_jump = 2;
}
}
void jumpstart(ENTITY* obj)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2)+4)
{
obj.jumpspeedold = obj.jumpspeed;
c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.in_jump = 1;
}
}
//================================================================================================================================================
//================================================================================================================================================
//================================================================================================================================================
void jump_event(ENTITY* obj, var frames, VECTOR* direct, var fall)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > obj.objekthoehe/2)
{
obj.jumpspeedold = obj.jumpspeed;
c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.in_jump = 1;
}
while(frames > 0 && obj.in_jump == 1)
{
jumpgo(obj);
c_move(obj, vector((direct.x*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
frames -= 1;
wait(1);
}
obj.roofdistframe = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdistframe > obj.objekthoehe/2)
{obj.in_jump = 2;}
if(fall == true)
{
while(obj.in_jump != 0 && obj.in_jump != 1)
{
if(obj.in_jump == 2)
{fallstart(obj);}
else if(obj.in_jump == 3)
{fallgo(obj);}
else if(obj.in_jump == 4)
{landing(obj);}
c_move(obj, vector((direct.y*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
wait(1);
}
}
c_move(obj, vector((direct.z*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
}
void jump_player(ENTITY* obj)
{
if(key_space == 1 && obj.jumpkeytrigger == 0)
{
if(obj.in_jump <= 0)
{jumpstart(obj);}
else if(obj.in_jump == 1)
{jumpgo(obj);}
}
else if(key_d == 0 && obj.in_jump == 1)
{obj.in_jump = 2;}
else if(key_d == 0 && obj.jumpkeytrigger == 1)
{obj.jumpkeytrigger = 0;}
obj.roofdistframe = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.in_jump == 2)
{fallstart(obj);}
else if(obj.in_jump == 3)
{fallgo(obj);}
else if(obj.in_jump == 4)
{landing(obj);}
else if(obj.roofdistframe > obj.objekthoehe/2 && obj.in_jump != 2 && obj.in_jump != 1)
{obj.in_jump = 2;}
}
objekterklärung | Info about variables: .gewicht => Gewicht in Kg, weight in kilo .fallspeed => Startet bei 1 steigt im fall, starts at 1 and increases during fall .roofdist => Entfernung zu Boden und Decke, distance to roof and floor .in_jump => Schalter für Phasen, Switch for Jump/fall phases .objekthoehe => 2* obj.max_z bulleter = Später für Bullet Time, need for bullet time later ich hoffe das uns wer helfen kann ^^" i hope that there´s someone who can help us.
Last edited by Espér; 07/24/11 21:54.
|
|
|
Re: Problem with Jump/Fall Code [GER/ENG]
[Re: Espér]
#379092
07/29/11 14:11
07/29/11 14:11
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
Example Screenshots of my problem: CORRECT: WRONG (the problem):  sometimes, the object falls through the floor.
Last edited by Espér; 07/29/11 14:13.
|
|
|
Re: Problem with Jump/Fall Code [GER/ENG]
[Re: Espér]
#379097
07/29/11 14:34
07/29/11 14:34
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
Hey dude, I'll try to help you with this. I'm gonna take a look. Last time I had a problem with movement, after which I've frozen my project. I asked here for help, but no one did, I couldn't fix problem myself, so project was canceled. I hope, that wont happen to your project, cause I'm willing to help you with your project  One thing I wanted to ask you about, why don't you use PhysX for this movement? It'll be better. You can find example here: PhysX for 2D sidescroller Or in the AUM 100, it's called "Rigid for 2D".
|
|
|
Re: Problem with Jump/Fall Code [GER/ENG]
[Re: 3run]
#379104
07/29/11 15:19
07/29/11 15:19
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
cause i´ve no clue how to do that... Dunno if it´s gravity.. PS.:This code is JUST FOR jumping.. The movement code is another. in jump, i trace to the roof and ask for the distance to it. if it´s far enough, i move the object upwards (and sideways if left/right is hitten). when jumpspeed is at it´s minimum value (10) or the distance to the roof is to small, falling starts. Now the fall code is the same as jumping.. checking distance to the floor, increasing fallspeed (max 100). If the distance to the ground is to small, the landing starts (later i want to check speed there, and play 4 different landing animations for the object). so the code is cut into the following parts (chronological): jumpstart => jumpgo => fallstart => fallgo => landing the additional functions are: jump_player => the process while the player is jumping (switching phases, aksing if space is still pressed) jump_event => make any other object jump the current code:
void landing(ENTITY* obj)
{
obj.fallspeed = obj.fallspeedold;
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
while(obj.roofdist > (obj.objekthoehe/2))
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
c_move(obj, vector(0, 0, -(5*(bulleter/100))*time_step), nullvector, GLIDE | IGNORE_PASSABLE | USE_POLYGON);
wait(1);
}
//obj.z += obj.objekthoehe/2;
obj.in_jump = 0;
}
void fallgo(ENTITY* obj)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2))
{
c_move(obj, vector(0, 0, -(obj.fallspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.fallspeed += (obj.gewicht/10.5)*time_step;
obj.fallspeed = clamp(obj.fallspeed, 0, 100);
}
else if(obj.roofdist <= (obj.objekthoehe/2))
{
obj.in_jump = 4;
}
}
void fallstart(ENTITY* obj)
{
obj.jumpspeed = obj.jumpspeedold;
obj.fallspeedold = obj.fallspeed;
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2))
{
c_move(obj, vector(0, 0, -(obj.fallspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.fallspeed += (obj.gewicht/10.5)*time_step;
obj.jumpkeytrigger = 1;
obj.in_jump = 3;
}
}
void jumpgo(ENTITY* obj)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2) && obj.jumpspeed > 10)
{
c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.jumpspeed -= (obj.gewicht/10.5)*time_step;
}
else if(obj.roofdist < (obj.objekthoehe/2))
{
obj.in_jump = 2;
}
else if(obj.jumpspeed <= 10)
{
obj.in_jump = 2;
}
else
{
obj.in_jump = 2;
}
}
void jumpstart(ENTITY* obj)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > (obj.objekthoehe/2))
{
obj.jumpspeedold = obj.jumpspeed;
c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.in_jump = 1;
}
}
//================================================================================================================================================
//================================================================================================================================================
//================================================================================================================================================
void jump_event(ENTITY* obj, var frames, VECTOR* direct, var fall)
{
obj.roofdist = c_trace(obj.x, vector(obj.x, obj.y, obj.z+9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdist > obj.objekthoehe/2)
{
obj.jumpspeedold = obj.jumpspeed;
c_move(obj, vector(0, 0, (obj.jumpspeed*(bulleter/100))*time_step), nullvector, IGNORE_FLAG2 | IGNORE_PASSABLE | USE_POLYGON | IGNORE_YOU | GLIDE);
obj.in_jump = 1;
}
while(frames > 0 && obj.in_jump == 1)
{
jumpgo(obj);
c_move(obj, vector((direct.x*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
frames -= 1;
wait(1);
}
obj.roofdistframe = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.roofdistframe > obj.objekthoehe/2)
{obj.in_jump = 2;}
if(fall == true)
{
while(obj.in_jump != 0 && obj.in_jump != 1)
{
if(obj.in_jump == 2)
{fallstart(obj);}
else if(obj.in_jump == 3)
{fallgo(obj);}
else if(obj.in_jump == 4)
{landing(obj);}
c_move(obj, vector((direct.y*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
wait(1);
}
}
c_move(obj, vector((direct.z*(bulleter/100))*time_step, 0, 0), nullvector, GLIDE | IGNORE_PASSABLE | IGNORE_FLAG2);
}
void jump_player(ENTITY* obj)
{
if(key_space == 1 && obj.jumpkeytrigger == 0)
{
if(obj.in_jump <= 0)
{jumpstart(obj);}
else if(obj.in_jump == 1)
{jumpgo(obj);}
}
else if(key_space == 0 && obj.in_jump == 1)
{obj.in_jump = 2;}
else if(key_space == 0 && obj.jumpkeytrigger == 1)
{obj.jumpkeytrigger = 0;}
obj.roofdistframe = c_trace(obj.x, vector(obj.x, obj.y, obj.z-9000), IGNORE_PASSABLE | IGNORE_FLAG2 | USE_POLYGON);
if(obj.in_jump == 2)
{fallstart(obj);}
else if(obj.in_jump == 3)
{fallgo(obj);}
else if(obj.in_jump == 4)
{landing(obj);}
else if(obj.roofdistframe > obj.objekthoehe/2 && obj.in_jump != 2 && obj.in_jump != 1)
{obj.in_jump = 2;}
}
and here the function for creating an object (not finished yet). Later it will include the equipment codes..etc, too.:
function obj_create(STRING* filename, VECTOR* position, VECTOR* rotation, var gewichtung, var sprungkraft)
{
ENTITY* creator;
if(filename != NULL)
{
creator = ent_create(filename, position, NULL);
}
else
{
creator = ent_create(CUBE_MDL, position, NULL);
}
vec_set(creator.pan, rotation);
c_setminmax(creator);
creator.objekthoehe = (creator.max_z*2);
creator.gewicht = gewichtung;
creator.in_jump = 0;
if(sprungkraft != NULL)
{
creator.jumpspeed = sprungkraft;
}
else
{
creator.jumpspeed = 50;
}
creator.jumpspeedold = creator.jumpspeed;
creator.jumpkeytrigger = 0;
creator.fallspeed = 1;
return(creator);
}
Last edited by Espér; 07/29/11 15:23.
|
|
|
Re: Problem with Jump/Fall Code [GER/ENG]
[Re: Espér]
#379105
07/29/11 15:23
07/29/11 15:23
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
When does player fall throw the ground? On landing? Or while walking? About using defines as a vectors, that's simple as hell:
#define dist_x skill1
#define dist_y skill2
#define dist_z skill3
function blahblah
{
while(1)
{
my.dist_x = 10 * (key_w - key_s) * time_step;
my.dist_y = 10 * (key_a - key_d) * time_step;
my.dist_z = 0;
c_move(my,my.dist_x,nullvector,INGNORE_PASSABLE|GLIDE);
wait(1);
}
}
|
|
|
|