4 registered members (ozgur, Ayumi, VHX, monarch),
1,161
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Detecting ground.
[Re: jfizer]
#150346
08/27/07 07:34
08/27/07 07:34
|
Anonymous
Unregistered
|
Anonymous
Unregistered
|
result = c_trace(vector(my.x,my.y,my.z - z_offset),vector(my.x,my.y,my.z - 4000),IGNORE_ME | IGNORE_PASSABLE ); if (result < 3 ) {force.z = -1 *result;} else{force.z -= 6 * time_step; force.z = maxv(-30,force.z);} velocity.z += (time_step * force.z) - (minv(time_step*0.7,1) * velocity.z); move.z = velocity.z * time_step;
c_move(my,vector(0,0,move.z),nullvector,IGNORE_PASSABLE| GLIDE); result = trace(vector(my.x,my.y,my.z - z_offset),vector(my.x,my.y,my.z - 4000)); if (result < 0) { my.z -= result; velocity.z = 0; } }
KHmovement turorial script used on my project a side from a samall jump out of the ground it works perfect. I changed it a little. Download the tutorial, Same methoid is used a lot by others.
hope I help sorry if not
Last edited by Malice; 08/27/07 07:37.
|
|
|
Re: Detecting ground.
[Re: Metal_Man]
#150351
08/28/07 00:39
08/28/07 00:39
|
Joined: Aug 2007
Posts: 21
jfizer
OP
Newbie
|
OP
Newbie
Joined: Aug 2007
Posts: 21
|
Quote:
floor_dist is great, unless you have model/entity/terrain floors. floor_dist only detects blocks, but it works very well if only block floors are used
Yea, no good for me. Need to be able to detect more complex objects.
|
|
|
Re: Detecting ground.
[Re: redgecko]
#150353
08/28/07 20:29
08/28/07 20:29
|
Joined: Aug 2007
Posts: 27
Memphis
Newbie
|
Newbie
Joined: Aug 2007
Posts: 27
|
why check down by 5000? Code:
void player_gravity() { int z_offset = 0; var z_check[2]; //vector vec_set(z_check, my.x); z_check[2] -= 1; //check down by 1. z_offset = c_trace(my,z_check,IGNORE_ME + IGNORE_PASSABLE + ACTIVATE_SONAR + USE_BOX); if (0 == z_offset) { //nothing was hit. we are at least 1+ above land //let gravity kick in.... Move_Force[2] -= iGravity * 2 * time_step; //must be odd number ? na nm. player_state = ps_drop; } else { //we must of landed ;) //recover to jump... BUGGY if (Move_Force[2] < 0) { //ok we dropping. if (Move_Force[2] < -20) { //down force.... no more then 20, we can keep falling if on next check :> player_health += 0.80 * Move_Force[2]; if (player_health < 0) { player_health = 0; } } animatejump = 0; Move_Force[2] = 0; iRecoverJump = 8; //impossible to recover lol. player_state = ps_drop; // Move_Force[2] = 0; } if (iRecoverJump > 0) { iRecoverJump -= 1; } } return 0; }
heres what im using now, and it works perfect. no problems as of yet...
|
|
|
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.
|
|
|
|