wichiwichi Posted January 29, 2014 Share Posted January 29, 2014 ( This post is a follow up from this question http://www.html5gamedevs.com/topic/3319-newbie-racing-game-detecting-when-im-off-track/?hl=track ) So I have a car (a sprite) and the track (a group of sprites) and wanted to know when the car was off track. I was kindly given two solutions1) Use physics.overlap() or...2) If(game.physics.distanceBetween(car, track < 10) { // do stuff in here } So the problems I'm having with these solutions are the following:1) physics.overlap() works perfectly when all the car is off the track, but it's not realistic to have 80% of the car off the track and still be detected as being on the track. So I've been looking for a solution like the one given in collision(), where you can detect where the collision has happened. But overlap() seems to only be able to give a boolean value. 2) physics.distanceBetween: it gives me the distance between the car and the first sprite of the group (coordinates 0,0) but not the current sprite I'm on. Even if it worked I wouldn't know how to calculate the distance between the car and the LATERAL zones. Is that possible? I've also been wondering whether I could do some other trick. Is is possible to create a car formed by the sprite itself and 4 invisible "bodies" (don't know what I'm looking for) so that I could detect independently if a wheel is outside the track? Thaaank you so much, I'm enjoying a lot Phaser by the way Link to comment Share on other sites More sharing options...
jcs Posted January 29, 2014 Share Posted January 29, 2014 you could create your car as a Group, consisting of multiple Sprites - one for each tire, one for the body, etc. you could then check each tire individually. Heppell08 and wichiwichi 2 Link to comment Share on other sites More sharing options...
Heppell08 Posted January 29, 2014 Share Posted January 29, 2014 Yeah I'm with JCS on that one. A group is the best way for that. wichiwichi 1 Link to comment Share on other sites More sharing options...
wichiwichi Posted January 30, 2014 Author Share Posted January 30, 2014 I think I tried this kind of solution but as it did not work (my mistake) I stopped. I'll try harder then Thaaank you both of you Link to comment Share on other sites More sharing options...
Recommended Posts