Jump to content

Collide Rotated Rectangles


Recommended Posts

In fact I think I am doing something a bit unusual wich involve a lot of rotation

and I understood it would be rather difficult to do in a physic engine.

It needs to stay quite simple that's why I thought I could manage it all by my self.


Check it there, just click to jump:




Obviously, the bounding box is problematic

How would you group the rotating obstacles and then check for collisions for the character ?



Link to comment
Share on other sites



I think you didin't hit the right source. If you don't want to use P2 physics. Just stick to arcade for other stuff and prepare your own collision check. There are numerous ways to go with for rotated rectangles, just pick one and go for it. I'd recommend using separating axistheorem (SAT), which is probably the most common one and works great.


If you are worried about complexity, then don't be it's really simple!


Basically you just check wheter there is free 'space' between two objects, that's all  - Ha! quite simple isn't it.


Here are some source1, souce2 with a nice explanation (first one seems easier to read and understand ;-)) which I just googled (google for more on your own), you can also find dozens of prepared JS functions based on SAT where you just need to change a few vars to phaser ones, and you are ready to go!


Just prepare your own collision function and if you are having some troubles coding section here or stackOverflow is the place to go to and settle it down.



With your second problem about crashing in midair (?) I don't really understand what exactly you are asking, maybe you should provide some sample situation (nothing beats nice pictures - screen shots) with some code?

Link to comment
Share on other sites

Hey man, thanks for all 


I tried to look in for SAT and indeed it looked a bit too complex for me, I wasn't able to find any JS functions by myself, I'll try and look deeper into that.

Concerning the bug, please just try the protoype in the link I provided (Just click to jump.)


Here the collision are working fine for a moment but at acertain point the character hit an invisible wall... and don't undestand why.

Also it seems that some of the obstacle are not showing up somehow....

Here is the source file 




Basically what I do is I create (reset) the obstacles at a specific place and attach them to the obstacles group and then correct the position so they won't jump ( becuase og the offset in world to local space and rotation). The function seems to be ok, but something is inconsistent no matter what I try ( I tried Arcade and and a very little bit of P2 and a few variation of a custom engine).



Thank you a lot 

Link to comment
Share on other sites

Try these links, MDN (Mozilla - javascript) and here you can check someone's SAT in js. In theory it's not that complex, you jsut need to write a few lines that's the other side of that ;-). Btw that js example is large because they test for different polygons, comments and other tweaks. Maybe even some js library on github. I don't even think you need to write the whole thing yourself, just check the links, learn from their code, copy what you need, tweak it ;-).

Link to comment
Share on other sites

I have been looking into these, but I am having a hard time understanding all that.

So I am going back to p2 for know

I managed to collide rotating rectangles.


My problem now is how to rotate am object around another, is the "revolute constraint" the right and only way to go ?

Link to comment
Share on other sites


  • Recently Browsing   0 members

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