Object sensing itself with the Near sensor

I have game set up where you click the ground and a building appears beneat your mouse (on the ground model). That script is working spectacularly. The next step is disallowing building placement on top of eachother. I figure there are two ways to do this. Grid placement or free placement. For grid placement I think I would need to be able to put all of the faces in the ground model into an array and turn each face on and off as things are placed on them or removed from them. Haven’t looked into how that might be done, yet.

I’m trying free placement, though, which currently allows you to drop a building half-way on top of another building, as long as you click on the ground next to an existing building (so they are partially merged). I’m trying to use a Near sensor attached to an End Object actuator (I look for the building being near another building with the property “building”). Currently, if I set the sensor distance too high, buildings terminate regardless of their proximity to another building (that number seems to be .999+). If I drop it below that value, buildings still merge and only delete if they’re really close. Anyway, if you can understand what I’m talking about, where I should I look to sort out what’s happening?

If all else fails I’ll drop “bases” first, which will be dirt meshes or some such, then child the buildings on top of those (so the base will be much larger in area than the building, allowing merging of bases but not buildings).

I would not use near,

I would use a “dummy” building that if conditions are not correct, does not spawn the building,

but the “dummy” can check around it with a ray, and make sure conditions are right,

another option is a “Cube ring” collider,
basically you have a cube that is ghost “bob” we will call it
invisible , in the center of building 1

then the “dummy” spawns a cube that is X size and again, invisible and ghost, if it collides with
“Bob” then no spawning building :slight_smile:

I was thinking something similar with the base. Except the base would be permanent. Then I’d also be able to use detailed ground models beneath buildings, to give the area a populated look. Nice to see I might be on the right track, though.

It occurs to me I’d still need to use some kind of indicator, though. Probably your cube. Replace the meshes of all cubes with some bright green box or something, when in building-placement mode.

Yeah,

have you looked @ real time terrain mod? you could have another tool that is “flatten”

I assume you are working on a game on the vein of sim-city.

I’d make an invisible sensor object cast a ray on the spot clicked, firing on the directions you want to check, and check for the space needed. If the ray doesn’t hit anything in an area, build it, else, don’t.

Or you just make a sensor object follow wherever you move the mouse, and check for the collisions, like in sim city, you see a ghosted version of the building you want changing colors if it can be built or not. Make it a basic invisible shape.

I wouldn’t put ghosts in a placed object, because you could end up with an immense collection of them, and that could be a hit for the system.

I know that a collision “Box” is much less CPU then a near sensor,

and a ray is better, but they can be tricky…

I tried doing the ghosted version of the building. But I was building on top of what I’d already done and it got messy. Gonna start from scratch tonight. Thanks a lot guys.