Jump to content

Collision with 45 degree slopes


JackBid
 Share

Recommended Posts

What I am trying to achieve is when a bullet is fired at a 45 degree slope, it bounces off at a 90 degree angle, this may be clearer looking at the attached image.

 

As you can see you would expect the bullet to bounce off at a 90 degree angle when it collides with the slope. I have all the logic and code ready to bounce the bullet off at this angle, my problem is that the bounding box around the slope is square or rectangular, as a result the bullet bounces off the slope before it actually collides with the pixels. I read in the forums earlier that phaser only supports square/rectangular collision. But how else would I be able to achieve this in my game, it does not need to be perfect, but just passable? 

post-5150-0-81460700-1387058631.png

Link to comment
Share on other sites

I saw you got this workable for your Ludum Dare game.

How did you go about it?

I probably would have just done an overlap test and changed the bullet velocity based on the frame or rotation of the angled surface.

Yeah pretty much, I checked what angled surface ii was (eg. if the bullet is moving up and should be reflecting to the right) and then I would center the bullet in the bounding box of that object, remove all velocity, rotate it to point in the right direction and add a new velocity. This does mean that the way the bullet reflects is not correct in terms of physics, but it is passable as the bullet moves fast and the user can barely notice the change. It is very simple and works surprisingly well, especially as I spend a while trying to think of more complex ways to achieve this!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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