Author Topic: find adjacent bricks  (Read 1062 times)

sort of like getUpBrick() but instead finds any bricks that are directly connected to its collision box. is this already a function or will i have to do some sort of container raycast to look for things

Use a box search that's like 0.1 units larger than the brick, there is no default function for this

Use a box search that's like 0.1 units larger than the brick, there is no default function for this
This is more-or-less what I would do. Try this:
Code: [Select]
function getUpBrick(%brick) {
%db = %brick.getDatablock();
%box = 0.5 * %db.brickSizeX - 0.05
SPC 0.5 * %db.brickSizeY - 0.05
SPC 0.1;
%boxPos = vectorAdd(%brick.position, "0 0" SPC (0.1 * %db.brickSizeZ + 0.1));
initContainerBoxSearch(%boxPos, %box, $TypeMasks::fxBrickObjectType);
while (isObject(%b = containerSearchNext()))
%bricksFound = %b SPC %bricksFound;
%bricksFound = rTrim(%bricksFound);
return %bricksFound;
}
where %brick is the brick you want to search above. The container box is shaped and positioned so that the function only finds bricks which are a single stud above the given %brick, and so that the %brick itself isn't included in the container. I tested this function, and it worked for me.

but what if the collision isnt rectangular or the size of the brick bounds

   initContainerBoxSearch(%boxPos, %box, $TypeMasks::fxBrickObjectType);
I don't know what you're using this for, but if you want to detect non-raycasting bricks as well, use $TypeMasks::fxBrickAlwaysObjectType.
sauce

but what if the collision isnt rectangular or the size of the brick bounds
i meant bounds sorry, not collision

but what if the collision isn't rectangular or the size of the brick bounds
Oh, right. I didn't think about that. Yeah, it (obviously) doesn't work very well for that.

I don't know what you're using this for, but if you want to detect non-raycasting bricks as well, use $TypeMasks::fxBrickAlwaysObjectType.
sauce
I just repurposed this code from another project that didn't need to detect non-raycasting bricks. What you suggest here is probably better for the OP's purposes.

also btw if the brick allows bricks to be built within the bounds (think arch bricks or door bricks that when open overlap other bricks) it will find those too.