lightmap Posted November 7, 2018 Share Posted November 7, 2018 (edited) Hello is there any functions to include/exclude Bodies from collision between? from code only like A.include(B); A.include(C); C.exclude(B); D.all(); D.exclude(A); seen no advanced usage in whole SDK of setPhysicalMask() only save/load seen https://developer.unigine.com/en/docs/2.7.2/principles/bit_masking/?words=physics%2Cmask%2Cphysic#highlight so exclude for C must remove all bits of B mask, but left A bit to collide then A must have 2 bits set (one for B, one for C) what about D? A - 1100 B - 1001 C - 0110 D - 0011 any suggestion about code inside .include/.exclude/.all ? or there another way? Edited November 8, 2018 by lightmap Link to comment
fox Posted November 8, 2018 Share Posted November 8, 2018 Hi Lightmap, Let's get something clear first. In your post you mention the setPhysicalMask() method while writing about managing collisions. Collisions are controlled by the Collision Mask, not the Physical Mask. So, you want to implement some sort of "friendly" methods (include, exclude and all), that would set up all necessary bits in the collision mask for bodies, please correct me if I'm wrong. I'm afraid it is not possible the way it works now. CollisionMasks are set for collision shapes, not for bodies (each body may have several collision shapes). Keep in mind that shapes can collide with other shapes and with surfaces of non-physical objects (with no body and no shape assigned). So a method like the one you offer would have to consider all these things and remember all previous settings. One question: how do you know which bits to remove and which of them to set? (taking into account all previous settings including the ones for surfaces) And in your case, suppose that C - 1110, what if I call C.exclude(A); It will remove all bits of A including the first one? But it is used for B as well, what if I don't want that? Guess the only way to manage selective collision detection from code is via the Shape::setCollisionMask() and Object::setCollisionMask() methods, provided that you determine which bits for which shapes or surfaces are to be set and which of them are to be cleared yourself (it'll be easier if you make a collision table for that). You can use some enums to define collision presets for various types of objects according to your logic and then use them to improve code readability. You can also check out the usage example on selective surface-base collision detection. Thank you! Link to comment
lightmap Posted November 8, 2018 Author Share Posted November 8, 2018 (edited) Hello yes its Collision Mask not Physical Mask yes setting collision mask for body sets mask for all its shapes (its tricky if there already some flags are set and for some shapes not) what analyses of bitsets in include/exclude is not clear for now, maybe it easier with tags (include/exclude by tag) at simplest I need button that setup bits for two colliding objects to exclude each other only I've seen required functionality in UE https://youtu.be/1avvVfvK-nc?t=1564 <- select two bodies and press "Disable collision" - friendlier for content creation than managing bits C was 0110 not 1110 and after C.exclude(A) must become 0010 if C 1110 then to exclude A(1100) and have B(1001), C must become 0001, without B C=0010 in general 'exclude' may change C bits, A bits or even change all bitmasks, but how to get it in code needs to think, or switch from bitmasks to something easier to manage thanks Edited November 8, 2018 by lightmap Link to comment
Recommended Posts