2 registered members (7th_zorro, howardR),
1,001
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
C_Trace to Ground
#334391
07/22/10 20:37
07/22/10 20:37
|
Joined: Jul 2008
Posts: 168
82RJZAE
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 168
|
Hi, I am coding a basic movement script and am having some difficulties with the c_trace function. It is not returning the value that I thought it should. For example, when I place the player on a block in the level, it returns a value of about 40. This only occurs when the level is first started. The movement code seems to function fine after the first "drop" into the level. I am using the following line to trace the distance to the ground:
distance_to_ground = c_trace(my.x, vector(my.x,my.y,my.z-500), IGNORE_ME | IGNORE_PASSENTS | IGNORE_PASSABLE | IGNORE_SPRITES | USE_BOX);
After that, I use the following code to simulate the acceleration due to gravity:
if(distance_to_ground >= 0)
{
accelerate(move_to_vector.z, (-3 * time_step), 0);
if(move_to_vector.z < (distance_to_ground * -1))
{
move_to_vector.z = distance_to_ground * -1 * time_step;
}
}
else
{
move_to_vector.z = -1 * distance_to_ground;
}
...
c_move(me, move_to_vector, nullvector, GLIDE | IGNORE_SPRITES | IGNORE_PASSABLE);
In the above image, the player flies into the sky because c_trace returns a negative value (distance_to_ground = -40). If I place the player 1 quant above the ground in WED, he will fall down at a high move_to_vector.z value (= -52). Any suggestions that might fix this?
|
|
|
Re: C_Trace to Ground
[Re: 82RJZAE]
#334418
07/23/10 03:13
07/23/10 03:13
|
Joined: Jan 2002
Posts: 300 Usa
Rich
Senior Member
|
Senior Member
Joined: Jan 2002
Posts: 300
Usa
|
I think this is becuase c_trace traces from the model's origin, and not it's "feet". Try this for your trace (untested):
distance_to_ground = c_trace(vector(my.x,my.y,my.z+my.min_z), vector(my.x,my.y,my.z-500), IGNORE_ME | IGNORE_PASSENTS | IGNORE_PASSABLE | IGNORE_SPRITES | USE_BOX);
A8 com / A7 free
|
|
|
Re: C_Trace to Ground
[Re: tD_Datura_v]
#334589
07/24/10 03:10
07/24/10 03:10
|
Joined: Jul 2008
Posts: 168
82RJZAE
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 168
|
The model should not show up as being that far into the ground though. At most I would suspect that if it fell into the ground c_trace would return a negative value not far from 0. Is there possibly something wrong with the way my c_trace was setup? When I use:
distance_to_ground = c_trace(my.x, vector(my.x,my.y,my.z-500), IGNORE_ME | IGNORE_PASSENTS | IGNORE_PASSABLE | IGNORE_SPRITES | USE_BOX);
and place the player flat on the ground in WED, the initial value distance_to_ground returns is -42.856. Whereas, if I place the player 1 quant above the ground in WED, the initial value distance_to_ground returns is 13.000. On the other hand, after the intial "drop" to the ground the distance_to_ground variable seems to function as it should! When the player's feet are on the ground, the distance_to_ground variable reads close to 0.
|
|
|
Re: C_Trace to Ground
[Re: 82RJZAE]
#334611
07/24/10 09:24
07/24/10 09:24
|
Joined: Dec 2006
Posts: 1,086 Queensland - Australia
Nidhogg
Serious User
|
Serious User
Joined: Dec 2006
Posts: 1,086
Queensland - Australia
|
Maybe the player's collision box is set wrong.
Windows XP SP3 Intel Dual Core CPU: E5200 @ 2.5GHz 4.00GB DDR3 Ram ASUS P5G41T-M LX PCIE x16 GeForce GTS 450 1Gb SB Audigy 4 Spyware Doctor with AntiVirus
|
|
|
Re: C_Trace to Ground
[Re: Nidhogg]
#334709
07/24/10 19:39
07/24/10 19:39
|
Joined: Jul 2008
Posts: 168
82RJZAE
OP
Member
|
OP
Member
Joined: Jul 2008
Posts: 168
|
Doing further tests I think the problem is the acceleration code. For example, if I press the TAB or F11 keys or anything that uses the beep function, during my descent to the ground, it causes move_to_vector.z to increase faster than normal. Could this problem be attributed to the time_step function?
EDIT: Removing time_step from the acceleration due to gravity code seems to reduce the initial speed the player accelerates downwards; however, I am still having the problem where c_trace is returning very low negative numbers when I place the model flat on a block in WED. If I jump, and allow the acceleration due to gravity place me back on the block, c_trace will return 0. Can anyone explain why this happens?
EDIT2: It turns out that the reason I was getting such a low initial value for c_trace was due to the bounding box exceeding the floor. Thank you everyone for your help!
Last edited by 82RJZAE; 07/25/10 21:07. Reason: The problem was discovered.
|
|
|
|