Collision testing before instantiating

Hello Crowd,

I’m scripting a generator. You type in the coordinates of beginning and end of a road, it generates the road and buildings beside it. My problem are the crossroads.
I have pics:

As you can see, at the crossroads the buildings overlap in a way and are also on the road.
How can I check before I instantiate the building, if there is anything (road or another house) nearby?

I tried it with Physics.OverlapSphere, but it doesn’t work. :expressionless:

You mentioned trying Physics.OverlapSphere() - do the road segments have colliders attached to them?

Well, they have a mesh collider
does that work or do I need to attach a rigidbody?
but anyway, it should work for the building collision anyway?

often mesh colliders are too complex sometimes it is good to add a simple collider like a cube

try destroying house which are in collision with roads.

@kiranmaya

I have trouble with even FINDING the houses who collide with eachother :wink:

you don’t even need colliders at this granularity. simply do if (Vector3.Distance(roadobj, thing)<amount)

Do a distance check between were you wanna place the house and the road. How hard can it be.

Probably a little harder than that :wink: I think in this case you’d probably at least want to use a point-segment distance check rather than a point-point distance check (otherwise, the results will likely be quite inaccurate).

You’re right though that colliders aren’t really needed for this.