sprite kit - Temporarily deactivate physical collision between two Nodes(Swift 2, IOS) -


i'm using spritekit, , i'm having trouble getting 1 of objects shoot out object, without colliding @ moment shoots it. however, no longer within range of contact each-other, want them able contact each-other rest of game.

here have tried-

    var allcategory: uint32  = 1;     var nillcategory: uint32  = 2;     var buffernode: sknode?      buffernode = self.childnodewithname("player")     buffernode!.physicsbody!.collisionbitmask = nillcategory;     buffernode!.physicsbody!.categorybitmask = nillcategory;     shootnewplayer(touchlocation)     runaction(skaction.sequence([skaction.waitforduration(1),skaction.runblock(removebuffer)])) } func removebuffer(){     buffernode!.physicsbody!.collisionbitmask = allcategory;     buffernode!.physicsbody!.categorybitmask = allcategory; } 

by default, objects in scene have collisionbitmask , categorybitmask of "allcategory." solution temporarily change categories nill. had absolutely no affect. want avoid solution since 1 second player no longer interact objects, cause bugs (with code above still interacts).

any ideas on how can object shoot new player without flying off in bazaar direction? thanks!

turn off object2 collision default. (do collisionbitmask = 0)

enable object contactbitmask flag object1.

on didendcontact method, enable collision object2 object1 when condition of object1 contacting object2 met.

this allow avoid things timers , checking update loop constantly.

in english, saying: when object 2 no longer touching object 1, object 2 able collide object 1.

depending on circumstance, may want remove contact test after enable collision


Comments