How to detect if a dummy is inside a cube?
How to detect if a dummy is inside a cube?
I want to check if a dummy is inside a cube. Initially, I thought of achieving this by checking for collisions between the dummy and the cube. However, I found that regardless of whether there is a collision between the dummy and the cube, the sim.checkCollision() function always returns -1.
Re: How to detect if a dummy is inside a cube?
Not sure if that's the intended behavior, as dummies have a "Collidable" flag, but that doesn't seem to affect sim.checkCollision which always returns 0.
You have two options, depending on how you want to treat a dummy.
If you want to treat the dummy as a point in space, you can simply check if its position relative to cuboid is inside its bounding box:
If you want to treat a dummy as a sphere, simply add a sphere of the desired size as child of it, with pose 0,0,0,0,0,0,1, so it will always have the same dummy's position, then use sim.checkCollision. (or you can use a modified version of above algorithm to take into account sphere size, it would only be slightly faster)
You have two options, depending on how you want to treat a dummy.
If you want to treat the dummy as a point in space, you can simply check if its position relative to cuboid is inside its bounding box:
Code: Select all
function isDummyInsideCuboid(dummy, cuboid)
local bb = sim.getShapeBB(cuboid) -- the 3 sizes of cuboid
local p = sim.getObjectPosition(dummy, cuboid) -- position of dummy in cuboid's reference frame
return math.abs(p[1]) <= bb[1] / 2 and math.abs(p[2]) <= bb[2] / 2 and math.abs(p[3]) <= bb[3] / 2
end