PlaceObjectOnGroundProperly? I don't think so!

I’m just joking,in other cases i’ll don’t try to help you ^^.

GET_GROUND_Z_FOR_3D_COORD(float x, float y, float z, float* groundZ, BOOL unk);

I see this returned value “float* groundZ” but i don’t see the second .Somebody else may can tell us .

The boolean say if ground is found at coords,else it retry until found.

And object spawn also underwater.

Tested with 3500 radius and seems to work pretty fine :drooling_face:

Edit: more the radius is high more the spawning time is long but it don’t affect the positioning of the objects.(Maybe due to my “slow” laptop? I don’t know… Must be tested on a better computer.)

Edit 2: The second value returned is maybe the boolean??

Interesting topic, since I have tried to do the same thing for ped and vehicle spawns around the map. I ended up using a variant of this:

https://github.com/crosire/scripthookvdotnet/wiki/Code-Snippets#force-groundztrue-water-depth-by-dilapidated
But I still will get peds falling through the map sometimes in certain areas, other areas work fine. With Peds and vehicles they will fall around 200m then get placed at the nearest vehicle node, so it is not a showstopper, but I should revisit this when I get more motivation. I tried adding HasCollisionForModelLoaded to it but still did not work all the time. @mikou does yuor script also work for peds and vehicles? I may be over-complicating it. I’m wondering now if I need to get the Groundz for x, y, 1000 then do RequestCollisionAtCoord(x,y,Groundz) before spawning the ped there as well, which is the only thing I have not tried yet.

I’ll try it for you cause i’ve a test code so a think this easier for me to test it instead of you to modify your whole script.I’ll tell you when done.

1 Like

Thanks. With peds I am finding groundz and then adding like 1 to 3 units to the groundz coordinate since iirc peds will spawn at their waist and will fall through.

So tested in the same conditions than objects and work perfectly with peds and cars also spawn in water(rivers,lakes etc).
To go further i’ve test in North Yankton and work to.
The only case that cause it do nothing is when in the middle of the ocean so this is no big deal ^^.

1 Like

cool. Do you mind sharing the code for the ped? Or is it exactly the same as above, except for CreatePed instead?

I will give it a try.

This is exactly the same,you just need to find a clever way to set the heading of peds.

1 Like

Also ground is always being returned as true as well? So all peds are spawning, except the ones in the ocean?

If in ocean,it look for an other place until ground == true.Is that what you ask for?

thanks. basically, is ground==true always true except for the ocean? So all peds spawn on the ground, none missing?

Yes all fine.

1 Like

You can now take a look at this for better informations :

You can ask me there if needed.

2 Likes