valueerror Posted April 2, 2014 Share Posted April 2, 2014 the docs say:Dispatched when a first contact is created between shapes in two bodies. This event is fired during the step, so collision has already taken place. The event will be sent 4 parameters: The body it is in contact with, the shape from this body that caused the contact, the shape from the contact body and the contact equation data array. why the hell do i need the shapes? can't i acces the shape of every body when i have the body? but hey.. the actual question is: how do i get both colliding bodies? fireball.body.onBeginContact.add(fireballCollision, this);function fireballCollision(target){ if (target.sprite && target.sprite.name == 'redtoad'){ killEnemy(target); //here i also want to kill the fireball so it can't harm anyone else ;-) } } Link to comment Share on other sites More sharing options...
rich Posted April 2, 2014 Share Posted April 2, 2014 Bodies can have many shapes within them - how would you know which of those shapes created the contact if we didn't give it to you? Anyway there are 2 events, one raised by P2.World which sends:callback(bodyA, bodyB, shapeA, shapeB, contactEquations);And one raised from the bodies themselves, which send:callback(bodyB. shapeA, shapeB, contactEquations) Link to comment Share on other sites More sharing options...
valueerror Posted April 2, 2014 Author Share Posted April 2, 2014 Bodies can have many shapes within them - how would you know which of those shapes created the contact if we didn't give it to you? Good point !! im sorry but i just cant figure out how to use you tip .. when are those two raised?how do i get the world to raise the one that sends both bodies.. ?? thank you! i am playing around with this because you once said that impact events are very expensive.. so i thought i'll try onBeginContact signals.. but if the world sends this on EVERY contact event and i have to compare "names" or "sprite keys" every time this signal is sent to determine if a specific action has to be triggered (because bullet hit enemy ) it feels like even more overhead .. or did i misunderstand you? Link to comment Share on other sites More sharing options...
JP91 Posted April 4, 2014 Share Posted April 4, 2014 This is a simple event https://googledrive.com/host/0B2Br6oKX-RFNTkpEYkpoTm5jUlU/index.html Link to comment Share on other sites More sharing options...
latestpost Posted March 19, 2015 Share Posted March 19, 2015 After digging around the equation you can get the 2 bodies in the collision usingequation[0].bodyA.parentequation[0].bodyB.parent wasi0013 1 Link to comment Share on other sites More sharing options...
valueerror Posted March 20, 2015 Author Share Posted March 20, 2015 @latestpost: this is probably the best answer to this.. thx! you know what i did until now?? here:fireball.body.onBeginContact.add(fireballCollision, fireball); //notice that instead of this i gave it the fireball as contextfunction fireballCollision(target){ thefireball = this; // here i grab the context (the fireball) and put it on "thefireball" if (target.sprite && target.sprite.name == 'redtoad'){ killEnemy(target); thefireball.kill(); } } wasi0013 1 Link to comment Share on other sites More sharing options...
Recommended Posts