简体   繁体   中英

how to detect two nodes collision point in Sprite kit and objective c

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.

didBeginContact is passend 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.

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........ :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM