Yanifska Posted May 18, 2015 Share Posted May 18, 2015 Hi thereIs there a way to check collisions of rotated rectangles in phaser ? ThanksYaniv Link to comment Share on other sites More sharing options...
rich Posted May 18, 2015 Share Posted May 18, 2015 Yes but you have to use the P2 Physics engine, not Arcade. Link to comment Share on other sites More sharing options...
Yanifska Posted May 18, 2015 Author Share Posted May 18, 2015 Are there any tutorial for this Engine, I am having a hard time with it.I was trying to build my own engine. But that's way too much for meThanks Link to comment Share on other sites More sharing options...
spencerTL Posted May 18, 2015 Share Posted May 18, 2015 The Phaser P2 examples are very comprehensive. Unless you are going for some really unusual stuff you should be able to combine the principles in them to achieve what you want.http://phaser.io/examples/v2/category/p2-physics Link to comment Share on other sites More sharing options...
Yanifska Posted May 18, 2015 Author Share Posted May 18, 2015 In fact I think I am doing something a bit unusual wich involve a lot of rotationand 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: http://www.yanivcahoua.com/examples/aeroboy/ Obviously, the bounding box is problematicHow would you group the rotating obstacles and then check for collisions for the character ? THANX GUYS !!! Link to comment Share on other sites More sharing options...
Yanifska Posted May 18, 2015 Author Share Posted May 18, 2015 Another problem I have, is sometime my character will crash into the air,It always will crash in the tenth obstacle that has just been generated,, but somehow is still far behind.So I don't understand why... Link to comment Share on other sites More sharing options...
AzraelTycka Posted May 18, 2015 Share Posted May 18, 2015 Hello, 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 More sharing options...
Yanifska Posted May 18, 2015 Author Share Posted May 18, 2015 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.)http://www.yanivcahoua.com/examples/aeroboy/ 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 http://www.yanivcahoua.com/examples/aeroboy/src/Game.js 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). AnywaysThank you a lot Link to comment Share on other sites More sharing options...
AzraelTycka Posted May 18, 2015 Share Posted May 18, 2015 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 ;-). Yanifska 1 Link to comment Share on other sites More sharing options...
Yanifska Posted May 19, 2015 Author Share Posted May 19, 2015 I have been looking into these, but I am having a hard time understanding all that.So I am going back to p2 for knowI 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 More sharing options...
Recommended Posts