Jump to content

Clearing up Arcade physics...


Recommended Posts

In order to keep my game lightweight, I've been meaning to use Phaser.Arcade. I know that you can only check against rectangle bodies, but I figured that works fine for me since all I have to do is check rotated rectangles against each other in my game. I don't want any sort of circular or polygonal checking.


My game is a top-down, free-roaming shooter, and some enemies rotate, which naturally alter their hitboxes.




Plus, I wanted enemies to have "aggro boxes" that look like this:




So I tried out this code for the aggro boxes:

var aggroBox1 = aggroBoxes.create(0,0,null);var aggroBox2 = aggroBoxes.create(0,0,null);aggroBox1.body.setSize(600, 600, this.width / 2, this.height / 2);aggroBox2.body.setSize(600, 600, this.width / 2, this.height / 2);aggroBox2.anchor.setTo(0.5, 0.5);aggroBox2.body.angle = 45;

However, I'm now learning that the "axis-aligned" in "axis-aligned bounding rectangles" means that there is no way to rotate the body, and that no angles are accounted for. So, to clear it up once and for all: Is this true? Should I redo my game with Ninja or P2? If so, which do you think is appropriate?

Link to comment
Share on other sites

Yes. AABB stands for "axially-aligned bounding-box" meaning that it doesn't rotate along with the sprite's rotation. Arcade physics, out of the box, will not rotate the physics bodies. For that you need P2.


BUT! You can set your own process and collide callbacks to do more fine-grained checking. e.g. set a larger rectangular bounding-box then, in your custom process function, check the actual Pythagorean distance or whatever you want.

Link to comment
Share on other sites

Oh man, part of the reason I loved using phaser is that I hate writing collision, animation and gamestate code. That is a nice idea, using the Phaser baseline and then extending it a bit...but just thinking about it makes me angry.


Well, thanks for the recommend! I'll check out P2 for now, and hopefully it won't add much bloat, since what I'm doing is kinda ambitious for a web game.


Just a quick question since there isn't much documentation on P2 out there: Do I have to make a whole ton of json files for simple hitbox data, or can I draw the rectangles in code like the example I provided for the aggroboxes? The latter sure would be nice.


I've unmarked this just until this is answered.

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


  • Recently Browsing   0 members

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