Jump to content

Checking collisions for a LASER


BenClarkson
 Share

Recommended Posts

Hi, I am new to phaser and I am programming a version of asteroids to get my sealegs. 

I wanted to take advantage of the bitmap data to create colorful gradient sprites for the ships lasers but I'm discovering the limits of arcade physics pretty quickly. 

I right now have a group of lasers which are bmd generated sprites. When the ship fires it grabs a random child and revives it, prints it, checks for bounds with the asteroid then is killed the next cycle. It looks great but with how the bounding box collision tests work — checking for collisions without physics — the laser collision test tells me true even when the laser clearly doesn't hit because of the ol' a^2 + b^2 = C^2.

I eventually want to turn the asteroid's physics bounds into polygons too for less hilariously random player deaths. 

I've read a bit about SAT.js but I can't find documentation for the support in PHASER and I'm unclear about the limits of arcade physics. What would checking phaser lines, or angled sprites for collision with a polygon look like?

Do I have to switch to PS to do line/ rectangle collision? Is this just a really silly way of doing this? Should I switch to an emitter (I might do that anyway for, like, really sweet machine gun effects). 

Thanks!

Link to comment
Share on other sites

For lasers yes, I would use line intersections. This will also come in handy when you make polygon bounds for asteroids. This example shows how you could go about doing it (look at the getWallIntersection function) so you could at some point replace the rectangle of lines it creates in that example with the shape of your asteroid.

 

Essentially you're throwing out all of the standard Arcade physics collision checks in favour of your own. If you want a pre-built solution then it may be worth instead looking at using P2 physics, which has proper support for polygon collisions.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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