Sign in to follow this  

Checking collisions for a LASER

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


Share this post

Link to post
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.

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.