2

I am working on game, in which i need different collision behaviours from different side,

Suppose there is a character when it collide to any other obstacle from down side, it will behave
differently.

when it collide to any other obstacle or object while it is at top and the obstacle or object is below it, then i need different behavior,

what is the best way to acheive it.-(void)didBeginContact:(SKPhysicsContact*)contact how it be
helpfull in my scenario

Thanks

umer sufyan
  • 1,005
  • 1
  • 12
  • 22
  • 1
    skphysicscontact gives you the contact point https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKPhysicsContact/Reference/Reference.html#//apple_ref/occ/instp/SKPhysicsContact/contactPoint Check where contact point is in relation to nodeA and nodeB position. Ie if posA.x < contactpoint.x and posB.x > contactpoint.x the contact was to the right of nodeA. – CodeSmile Jun 17 '14 at 06:47
  • Thanks your thoughts are helpful. – umer sufyan Jun 17 '14 at 07:05
  • One more points that is not relevant to my question, but i am confused little a bit, is that categroybitmask that decide for bodyA, and bodyB in SkphysicsContact.or in simple word what criteria decides that the body in contact is contact.bodyA or contact.bodyB? Thanks – umer sufyan Jun 17 '14 at 07:08
  • bodyA and bodyB are not deterministic, the desired node could be A one time, B the next time. Your code has to handle both cases. Bitmasks do not influence the order of nodeA and nodeB. How bitmasks work is explained in the skphysicsbody class reference. – CodeSmile Jun 17 '14 at 08:10

2 Answers2

1

You do not even need the contact point. The method called after you determine what came in contact has access to the nodes in contact. Therefore, you can just compare the x and y locations and handle them accordingly. You can then ignore collisionBitMask and replicate the collisions in the method called by contact.

meisenman
  • 1,818
  • 1
  • 15
  • 25
0

LearnCocos2D guided me in Right direction

skphysicscontact gives you the contact point developer.apple.com/library/ios/documentation/SpriteKit/… Check where contact point is in relation to nodeA and nodeB position. Ie if posA.x < contactpoint.x and posB.x > contactpoint.x the contact was to the right of nodeA.

Community
  • 1
  • 1
umer sufyan
  • 1,005
  • 1
  • 12
  • 22