Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (Nymphodora), 490 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Snap to Ground #405355
07/28/12 20:23
07/28/12 20:23
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
Hi, can anyone provide a snippet about how to snap a model to the ground using c_trace? I can't seem to get it to work.

Re: Snap to Ground [Re: 82RJZAE] #405356
07/28/12 20:34
07/28/12 20:34
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
To snap a variable, you can use this:
var snapped_x = grid_size * integer(nonsnapped_x / grid_size);


Visit my site: www.masterq32.de
Re: Snap to Ground [Re: MasterQ32] #405357
07/28/12 20:41
07/28/12 20:41
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
I guess what I really meant was that I have a model placed into the level via script and I would like to have that model either moved up (if it's inside the ground) or down (if it's above the ground) via changing its z coordinate using a c_trace.

Re: Snap to Ground [Re: 82RJZAE] #405358
07/28/12 20:50
07/28/12 20:50
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Then show us the code you already have. We will be glad if we can help you.


Always learn from history, to be sure you make the same mistakes again...
Re: Snap to Ground [Re: Uhrwerk] #405359
07/28/12 21:05
07/28/12 21:05
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
That's the thing; I'm a little confused as to where I should be tracing from to account for both cases of having a model placed in the ground or above the ground. I have tried tracing from my.x to a point below the character and I have tried tracing from the lowest vertex of the model to the ground both without getting the correct solution. My latest attempt was the following code:

Code:
VECTOR vec_min;
VECTOR vec_max;
wait(1);
c_setminmax(me);
vec_for_min(vec_min, me);
vec_for_max(vec_max, me);
result = c_trace(vec_max, vector(vec_max.x,vec_max.y,vec_max.z-1000), IGNORE_ME | IGNORE_MODELS | IGNORE_PASSABLE | USE_BOX | IGNORE_SPRITES); // trace from the origin to the floor and store the result
my.z -= target.z;
my.z += (vec_max.z-vec_min.z);


1. traced from the top vertex to a position below
2. lower the distance traced from the top vertex to the position below (c_trace returns the distance)
3. then add the height of the entity (max vertex - min vertex)

In theory, the above solution should work for models placed in the ground but it doesn't seem very efficient and it also doesn't work. tongue Any tips or better ways to approach this case?

Thanks for your replies!

Re: Snap to Ground [Re: 82RJZAE] #405361
07/28/12 21:16
07/28/12 21:16
Joined: Apr 2006
Posts: 159
Latvija
Arrovs Offline
Member
Arrovs  Offline
Member

Joined: Apr 2006
Posts: 159
Latvija
Tracing is good because USE_BOX uses box borders for distance(at least i think so).
But i think your code for placing object isnt exatcly right.
It should be as
Code:
vec_set(my.x, target.x);//place object at scanned point
my.z += my.min_z;//possible you can add some more quants if you vant it to not stuck in ground(if using c_move aftervards)


If my.min_z is negative just give -my.min_z;


Arrovs once will publish game
Re: Snap to Ground [Re: Arrovs] #405364
07/28/12 23:44
07/28/12 23:44
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I think you misunderstood the documentation on vec_for_min and vec_for max. These functions sets the given vector to the maximum and minimum of the entity in object space. A pretty simple approach to place an entity on the ground is to first lift it up by a certain value, like "my->z += some_distance". Then you can trace from the entities position in a downwards direction:
Code:
result = c_trace(my.x,vector(my.x,my.y,my.z-2*some_distance),IGNORE_ME | etc.);

You can then set the entities position to target and add entity.min_z to the z position of the entity.


Always learn from history, to be sure you make the same mistakes again...
Re: Snap to Ground [Re: Uhrwerk] #405366
07/29/12 03:56
07/29/12 03:56
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
That's true! I didn't consider that approach. Thanks! laugh


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