Detect object proximity to walls

Hi Folks,


I am trying to write something really simple - and use SpriteKit on this instance.

The way I did it on other platforms, is by having an invisible child "stick" sticking out a bit. By detecting collision between the invisible "sticks" I can tell wherether the object is close to the wall or not.

I am trying to replicate the same thing using SpriteKit. Of course, I'd prefer to have an invisible "beam" coming out of the object and giving me distance - but that's probably too much hassle.


I'd appriciate any ways to improve on my silly project I got so far.


http://cocoasmiths.com/2dKart_stuck.zip


Thanks.

Accepted Reply

I didn't download the project, but it seems like all you need to setup is a sprite with a physics body that is ignored for collisions but enabled for contacts. Look into categoryBitMask, collisionBitMask, contactTestBitMask.

Replies

I didn't download the project, but it seems like all you need to setup is a sprite with a physics body that is ignored for collisions but enabled for contacts. Look into categoryBitMask, collisionBitMask, contactTestBitMask.