Random Spawn near Players location

I want to spawn a car near the players location. The Problem here is the Collision detection. Is there something already implemented that I can use? I know that there is a “try to adjust location” option but the radius is really limited. Can I increase the radius? Or can I use the NavMesh to get the next free area to spawn a car?

Just get the component bounds in BP and spawn the car that far away ( you can spawn it somewhere else and move it to the player ):

bounds.JPG

Something like:

Thanks for your answer but how does this prevent a collision between the car and the enviroment?

No, I just thought you didn’t want it to kill the player :wink:

I’m not sure in that case…

Hmm, is there not a smart, easy way?

A one node solution? Not sure, I’d say no.

What you’re really looking for here is a volume large enough to fit the bounding box XY (rotated around Z probably, so more space than it seems needs to be checked) without intersecting any undesired geometry in a given radius away from the player. I do not know the math / method to pull it off properly (although it must have been done at some point - there is a paper on almost everything out there, it seems) but…

…if you need something quick and dirty, simplify & brute force it. Start placing a collision sphere in an orderly fashion in a radius around the player, as soon as one of them sticks - detects no overlapping elements, break the loop and that’s your free spot. When I think about spawning a car sized entity next to a player, I’d say 18 checks should be plenty to approximate whether there is a suitable spot; you can have more if you need more fidelity. This is probably not that inefficient too. On average you’ll skip more than half of those checks most likely.

Once you have that going, you can try to find wiggle room for the checks whose centre ended up being far from the closest collision point - these are still promising. Shift the sphere by that much in the opposite direction and check again. If no dice, move on to the next point in radius and do the collision there.

edit: pics

Thanks for your answer! I thought about a similar idea too but with box traces and in a spiral way around the character. I think I will improve this since it looks like there is not a ready to go node or something.