Reputation: 235
I have two SKSpriteNode's, i know how to detect if they are in same place, but I cant figure out how to detect in which place of node they have collision. I particular want to know one of nodes collision place, because I want to add different applyImpulse
on nodes height ends, so another node will change direction.
Upvotes: 2
Views: 923
Reputation: 8134
didBeginContact
is passed an SKPhysicsContact
when 2 bodies collide. SKPhysocsContact has a property contactPoint
which is a CGPoint
and is the contact point between the two physics bodies, in scene coordinates. From this and the positions of your 2 bodies when they collide, you could work out where exactly on the bodies the collision took place.
Upvotes: 2
Reputation: 7390
You can get the contact point like:
CGPoint collidedPoint = contact.contactPoint;
You can get the x & y points like below:
NSLog(@"collidedPoint x= %f | %f",collidedPoint.x,collidedPoint.y);
// Prints like: collidedPoint x= 424.855835 | 46.139378
Keep Coding........ :)
Upvotes: -1