I have two different .scn files with two different parent node with multiple childnodes. I have implemented collision delegates methods and it is getting called correctly. My intention is to find collision only if any child node from second .scn file collides with any child node or root node of first .scn file or vice versa.
But right now since in both the .scn files, all child nodes are closely placed, these delegates are always getting called providing contact.nodeA and contact.nodeB as two child nodes that collide with each other from same .scn file.
Is it possible to detect collision only if contact.nodeA is from different .scn file(can be any child node) and contact.nodeB is from different .scn file(can be any child node)?
Also i may add the node from first or second .scn file multiple times to the same scene. In this case it should detect collision between nodes of these two .scn files even if they are from same .scn file (added two times to scene), since i am adding it two times as a separate object
I have set the categorymask, collisionmask and contact mask as 1 in Xcode scene editor and have set the physics body to kinematic for all the child and root nodes of both the .scn files.
Every scene should have it's own
Category mask
(categoryBitMask
in code), while itsCollision mask
(collisionBitMask
) andContact mask
(contactTestBitMask
) should be equal to theCategory mask
of the other scene.Collision mask
of a node tells the physics world which categories of nodes (based onCategory mask
) should it collide with.Category mask
of a node tells the physics world to notify its delegate about the contact with certain categories of nodes.So in order to achieve what you want (given you want them to actually collide and not just detect that they've had a contact):
Nodes of scene 1:
Nodes of scene 2:
That way they would only collide with nodes from the other scene and not with their "sisters".
Remember that
Category mask
should be a power of 2 (2^0 = 1 and 2^1 = 2) so that you are be able to combine them by adding them up.For example, if you were to add the third scene, it should've had a
Category mask = 4
(2^2 = 4):Nodes of scene 1:
Nodes of scene 2:
Nodes of scene 3: