Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (7th_zorro, howardR), 1,001 guests, and 2 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
C_Trace to Ground #334391
07/22/10 20:37
07/22/10 20:37
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

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:

Code:
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:

Code:
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 Offline
Senior Member
Rich  Offline
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):

Code:
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: Rich] #334421
07/23/10 04:01
07/23/10 04:01
Joined: Nov 2007
Posts: 1,143
United Kingdom
DJBMASTER Offline
Serious User
DJBMASTER  Offline
Serious User

Joined: Nov 2007
Posts: 1,143
United Kingdom
You can also look up 'floor_dist' in the manual.

Re: C_Trace to Ground [Re: DJBMASTER] #334430
07/23/10 08:01
07/23/10 08:01
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
@Rich: When I used that trace it returned a value of -504.856 (-292.285 when the player was 1 quant above the ground in WED) for distance_to_ground. In other words, it still caused the player to fly into the sky. =P

@DJBMASTER: Interesting, but that function does not seem to offer as much freedom compared to the c_trace function.

Re: C_Trace to Ground [Re: 82RJZAE] #334557
07/23/10 22:05
07/23/10 22:05
Joined: Dec 2005
Posts: 116
T
tD_Datura_v Offline
Member
tD_Datura_v  Offline
Member
T

Joined: Dec 2005
Posts: 116
Probably, if c_trace returns a negative value (i.e. the model is IN the ground), the model should not be pushed OUT of the ground all in one frame. Instead, the model might be pushed OUT of the ground gradually over time, just as it is probably dropped gradually over time.


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
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

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:
Code:
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 Offline
Serious User
Nidhogg  Offline
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
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

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.

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