Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Newbie -- racing game, detecting when I'm off track (part 2)


wichiwichi
 Share

Recommended Posts

( 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 solutions

1) 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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...