|
2 registered members (AndrewAMD, TipmyPip),
12,420
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Detecting ground.
[Re: Memphis]
#150354
08/29/07 05:53
08/29/07 05:53
|
Joined: Aug 2007
Posts: 21
jfizer
OP
Newbie
|
OP
Newbie
Joined: Aug 2007
Posts: 21
|
Quote:
why check down by 5000?
Because it is assumed that at some point the player is going to be in the air. 5000 is just a nice big number to use. If I only checked down by one, I would get zero as soon as the player was a distance of two away from the ground making it impossible to tell the difference between on the ground and at a distance of greater then one.
Whats more, we're checking from the center of the player object so there is a varriable distance between center and ground that needs to be calculated or offset. So in fact I never see a value of "zero" other then if the player is farther away then the distance I'm checking (5000). What I see if the distance from the player entity center to the ground +/- aorund 1 it seems.
And last but not least, rather then apply force to mimic gravity as in your code example, I just use the physics engine gravity constant and give the player mass.
ph_setgravity (vector(0, 0, -386)); phent_settype (my_entity, PH_RIGID, PH_SPHERE); phent_setmass (my_entity, mass, PH_SPHERE); phent_setfriction (my_entity, friction); phent_setdamping (my_entity, damping[0], damping[1]); phent_setelasticity (my_entity, elasticity[0], elasticity[1]);
....
if(!key_space) { jumping=0; } if(key_space) { if(!jumping) { vec_set(temp, my_entity.x); temp.z -= 5000; if(c_trace (my_entity.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS|IGNORE_SPRITES) <= 25) { phent_addvelcentral(my_entity,vector(0,0,250)); } } jumping=1; }
Last edited by jfizer; 08/29/07 06:00.
|
|
|
|
|
|