BenClarkson Posted May 29, 2014 Share Posted May 29, 2014 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 More sharing options...
lewster32 Posted May 29, 2014 Share Posted May 29, 2014 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. BenClarkson 1 Link to comment Share on other sites More sharing options...
BenClarkson Posted May 29, 2014 Author Share Posted May 29, 2014 Cool, I had taken a look at that before and never put two and two together (the answer is four)Thanks a lot. I am probably going to switch to P2 physics when I start my next project. Link to comment Share on other sites More sharing options...
Recommended Posts