Search code examples
sprite-kitskphysicsbody

Check for absence of contact


I'm developing a puzzle platform game using Sprite Kit (and its physics engine). My player's physics body consists of a large hitbox covering most of the sprite, and a wheel with a pin joint anchored at the bottom of the hitbox. Rotation is added to the wheel to make the player move across the screen.

I need to know if the player is on the ground, or has fallen off a ledge; I know how to check for a physics body contact, but is it possible to check for an absence of contact (i.e. when the wheel leaves the ground)? I can't rely on comparing the Y position from the last frame as there are sloped surfaces that the player climbs.


Solution

  • You can use the didEndContact:(SKPhysicsContact *)contact to check if the wheel is no longer contacting the ground. Same principal as the didBeginContact:(SKPhysicsContact *)contact just in reverse.