wichiwichi Posted January 24, 2014 Share Posted January 24, 2014 Hi there, I'm trying to code a racing game and I'm running into the following issue: I want to detect when I'm off track in order to apply some penalty to the player; I just can't do that. So first of all I've got the ground of Tank's example, which is added with the function land = game.add.tileSprite(0, 0, 800, 600, 'earth');Then I've got the track, which is a group track = game.add.group(); track.create(0, 0, 'tl90'); and so on...And finally I've got the car, car = game.add.sprite(0, 0, 'car'); car.anchor.setTo(0.5, 0.5); In the update function I tried game.physics.collide(car, track, collisionHandler, null, this); but with that line track and car collide, so I'm thinking it's not collide what I'm looking for. I tried to make the track immovable with track.body.immovable = true; but it didn't work either. Would someone point me to the function or an example of what I'm looking for? Thank you so much in advance Link to comment Share on other sites More sharing options...
jcs Posted January 24, 2014 Share Posted January 24, 2014 physics.overlap() will detect if two bodies overlap (intersect) without applying any physics collision to it... jerome 1 Link to comment Share on other sites More sharing options...
Heppell08 Posted January 24, 2014 Share Posted January 24, 2014 Use the aforementioned overlap and also another good idea is to use distancebetween. So if the distance is so much then fire a function in your update. Eg:If(game.physics.distanceBetween(car, track < 10) { // do stuff in here } all in your update. Link to comment Share on other sites More sharing options...
wichiwichi Posted January 24, 2014 Author Share Posted January 24, 2014 Thank you so much to both of you, that's exactly what I was looking for Link to comment Share on other sites More sharing options...
Recommended Posts