1
votes

So in my Space Invaders game, all collisions were working perfectly until I added a physics body created from a edgeChainFromPath which is a single line to represent the ground (an SKShapeNode created from 2 points). Now my invader bombs (which move via SKAction) notify when they hit the ground but my invaders (moved in update() by manually updating their positions) do not. My ship missiles (also moved by SKAction) DO notify when contacting an invader.

Question : if a physicsBody is moved manually and comes into contact with another physicsBody, is didBeginContact not called? (All physics interactions - bitMasks, delegates etc - are set correctly). I'm thinking the answer is 'No it's not' because that's the only explanation and makes sense picturing how Sprite/Kit probably works. I.e. A contact occurs when the SK engine itself moves a node and realises that it's physicsBody is being drawn on top of another physicsBody.

Edit - just realised that I have other physicsBodies in my scene that are stationary and that the invaders DO collide with, so it's not an SKAction thing. The difference might be that the new node I've added is an edge-based body belonging to an SKShapeNode, rather than a volume-based body for a SKSPriteNode, but nothing in the documentation that I can find states that this shouldn't work.

New question : Do volume-based bodies being moved manually not collide with stationary edge-based bodies?

1
Hi Steve, it's hard to help you if you use both SKAction and physics interactions/collisions (not recommended) , expecially if you involve the update method but without code I don't know so I could be wrong.Alessandro Ornano
@AlessandroOrnano - It's not what I though it was - see my edit. I've been adding bodies to this code and following a standard procedure - assign the category, set the bitmasks, add tests to didBeginContact and so far everything has worked first time, so my underlying code is good. I'm going to change the new edge-based body to a volume-based body to see if that changes things.Steve Ives
What's your current bitmask setup, are you filtering anything out in did begin contact?DreamerNo56
All my bitmasks check out and my checkPhysics() routine tells me that the invaders contact the ground. The invaders make contact with other physics bodies that they are moved into and other physics bodies make contact with the ground. My current theory is that it's because the ground is a very thin edge-based body onto which a volume-based body is being placed directly, so I need to check this.Steve Ives
Are you positive the physics interactions are set up correctly?Knight0fDragon

1 Answers

1
votes

Ok - my bad. The invaders' physicsBodies had dynamic=false. Every other sprite was dynamic, so all other collisions were working. My new shape was an edge-based body which also are dynamic=false.

Made that one change and all is Ok. I need to update my checkPhysics() routine to test for this.

Edit: I really should have seen this earlier - checkPhysics() was not printing that invader notifies when contacting ground, which I just put down to a glitch that I'd fix later. Whereas checkPhysics() deliberately doesn't report on nodes with dynamic=false. I think that when I wrote the function, I assumed that you'd set dynamic=false deliberately to not be involved in collision/contact detection. I should change it to print a warning.