Braxen

Bitmap collision maps?

Recommended Posts

I'm trying to port an old top down driving game that uses bitmaps (as big as the overworld screens) for collision checking, with altitude and road types. I've already rewritten the whole thing twice but I'm not satisfied with my solutions, and I'm considering doing it again but with Phaser this time.

Any pointers on how or if it's possible with the (arcade) physics engine? I like the feel of it.

The crucial thing is that if you try to drive off the road, the car should slide and turn automatically to get back on track - going on the grass is supposed to be impossible.

I've already written a custom python script to extract all the game assets and package them in atlases and sound sprites for instant use in Phaser (multipack support is needed!!), so i don't really want to abandon this again.

Share this post


Link to post
Share on other sites

Feels like I've tried everything now, i have the bitmap set up and i can get the pixel data where the player is, but i can't find any custom collision hooks in the arcade physics engine, and setting the old position after checking manually for values just makes the player stop on a dime.

Also, cool registration time ;)

Share this post


Link to post
Share on other sites
58 minutes ago, samme said:

Which part are you stuck on exactly?

Making it collide, preferably in a native way. The only thing I've managed to do is make the player stop at the hit point and set the velocity to 0, which is not what i want.

I'm open to using completely other methods of collisions, but i can't really find any other ones which can handle roads like this.

This is how the collisions should look, i'm only holding forward.

Share this post


Link to post
Share on other sites
6 hours ago, samme said:

How does the car move?

My previous approach did the sin/cos thing with the speed and angle to move forward, this current one uses phaser's built in functions for moving with the arcade physics.

I can change anything, as long as it works.

Share this post


Link to post
Share on other sites

You could get the pixel color from your map under the center of your car. Compare that pixel color with the color of the edge of your road to detect if you're colliding with it.

It might be easier if you had a black and white image that you use just for collision checks. Have the roads be drawn in black and detect collision with white pixels.

Share this post


Link to post
Share on other sites

You probably don't need the collide/overlap methods, which rely on sprite.body vs. sprite.body intersection checks. If you can detect "collisions" yourself already, keep doing that.

For reacting to the collisions, it depends on what you want to do, but here are a few examples:

  • Bounce the car back in the direction it came, by reflecting the velocity vector
  • Calculate a velocity vector back to the course, and apply it
    • immediately; or
    • by interpolating it with the current velocity; or
    • by tweening to it from the current velocity
  • Calculate a new position and move the car to it:
    • set body.moves=false
    • tween to the new position
    • set a new velocity
    • set body.moves=true

Share this post


Link to post
Share on other sites

I did actually manage to make it automatically turn by testing the front left and right point of the car and turning the other way. It's not optimal yet though, as you can't really turn at all when driving because it overrides everything else.

The difficult part of making it proper is how to calculate the reflection normal, because there are no walls to speak of, only pixels.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.