prevent the player from building stuff on an unequal terrain

if you want a clearer vision of what I want to do check Fallout4 building, here. or Osiris building here.

so what I am trying to do is to make a system allowing the player to build things on terrain. now doing that in theory is easy. I want to make a raycast, when the ray hits the terrain a building will show, you can rotate,and a click will add an instance of it (If you have a better way do share please :slight_smile: )

returning to the question; I want to prevent the player from building a building on an uneven terrain, with these notes in mind:

1- allow the player to build with a small amount of terrain noise ( you can build even if not 100% plain floor as long as its not too much or on a cliff or something)

2- a large object should be harder to build since it might be built over a larger terrain (hence more chance on being on an uneven terrain)

multiple solutions are more than welcome since it will be applied to our system. I want the best solution possible that fits our engine.

thanks :slight_smile:

Make four raycasts - one at each corner of the building you are trying to place. If the height of the hit point of all four raycasts (and/or the angle of all hit normals) is within a certain tolerance, then the terrain is flat enough for a building to be placed there.