Jump to content

Collision detection without defining polygon?


xacrox
 Share

Recommended Posts

Hello!

I am fairly new to the phaser framework. So please excuse my noob ignorance if this is an easy question. I know that adding collision on a object such can be easily done with:

game.physics.arcade.collide(gameObject1, gameObject2, collisionCallback, processCallback, context); 

However when you have an object like this ice spike:
post-10854-0-29948300-1412112686.png
You would likely need to define a polygon in order for proper collision detection. Which should theorectically be pretty easy considering it's pretty much a triangle.

My question is however... when I get into more unique elements say for example this water:
post-10854-0-29267200-1412112689.png

And I want to make only the non-transparent parts collide. Is there an easier way?
Is there a way to detect non-transparent pixels as opposed to defining each aspect by hand?

Hope this makes sense & thanks so much in advance!

 

Link to comment
Share on other sites

Not in Arcade Physics I'm afraid. Arcade is based on 'AABB' collision detection, which stands for Axis Aligned Bounding Box - basically all objects have a non-rotatable rectangle collision area, which is very fast, but obviously has limitations here. Often a tradeoff is made when trying to apply rectangles to triangular objects whereby the body size is reduced to provide coverage over the part of the triangle that matters.
 
post-7918-0-01837400-1408109510.png

 

If you really need non-rectangular collision bounds, you're going to have to use P2 physics instead of Arcade. Then you can define arbitrary simple polygons as collision hulls.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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