Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,078 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Detecting ground. #150345
08/26/07 17:34
08/26/07 17:34
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Can anyone think of a better method of detecting if an entity is on the "ground" or another object?


vec_set(temp, my_entity.x);
temp.z -= 500;
if(c_trace (my_entity.x,temp,IGNORE_ME|IGNORE_PASSABLE|IGNORE_MODELS|IGNORE_SPRITES) < 25)
{
// Do stuff
}


The problem with this is there seems to be a very inconsistant value returned from c_trace and even an object at total rest is not returning zero.

Re: Detecting ground. [Re: jfizer] #150346
08/27/07 07:34
08/27/07 07:34

A
Anonymous
Unregistered
Anonymous
Unregistered
A



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: ] #150347
08/27/07 08:29
08/27/07 08:29
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
If the entity is lit (UNLIT flag not set), and the ground is a level floor and not a model or terrain, you could also check its floor_dist parameter.

Re: Detecting ground. [Re: ] #150348
08/27/07 15:37
08/27/07 15:37
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Quote:

result = c_trace(vector(my.x,my.y,my.z - z_offset),vector(my.x,my.y,my.z - 4000),IGNORE_ME | IGNORE_PASSABLE );




Whats z_offset set to and how did you arive at its value?

EDIT: Also, the Kingdom of Hearts Movement Tutorial dosn't contain any instance of c_trace that I can find.

Last edited by jfizer; 08/27/07 15:57.
Re: Detecting ground. [Re: jfizer] #150349
08/28/07 00:13
08/28/07 00:13
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

Joined: Aug 2007
Posts: 21
Putting the test output from the ground detection in a panel seems to give better results. I guess the watched varriables aren't updating quick enough.

Re: Detecting ground. [Re: jfizer] #150350
08/28/07 00:24
08/28/07 00:24
Joined: Mar 2007
Posts: 75
M
Metal_Man Offline
Junior Member
Metal_Man  Offline
Junior Member
M

Joined: Mar 2007
Posts: 75
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

Re: Detecting ground. [Re: Metal_Man] #150351
08/28/07 00:39
08/28/07 00:39
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

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: jfizer] #150352
08/28/07 04:01
08/28/07 04:01
Joined: Jul 2005
Posts: 14
R
redgecko Offline
Newbie
redgecko  Offline
Newbie
R

Joined: Jul 2005
Posts: 14
The following should work, storing the computed distance in the variable distance_to_ground. However, when I've displayed the value in a panel it does seem to start fluctuating after the player is stationary for a few seconds. Not sure why!

vec_set (temp.x, my.x); // copy player's position to temp
temp.z -= 5000; // set temp.z 5000 quants below player's origin

// compute the distance to ground
distance_to_ground = c_trace (my.x, temp.x, ignore_me | use_box);

Re: Detecting ground. [Re: redgecko] #150353
08/28/07 20:29
08/28/07 20:29
Joined: Aug 2007
Posts: 27
M
Memphis Offline
Newbie
Memphis  Offline
Newbie
M

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...


Meka][Meka || TeamElite Owner Meka-Meka Programmers
Re: Detecting ground. [Re: Memphis] #150354
08/29/07 05:53
08/29/07 05:53
Joined: Aug 2007
Posts: 21
J
jfizer Offline OP
Newbie
jfizer  Offline OP
Newbie
J

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.

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1