Jump to content

Physics Bodies Not Moving With Sprite Group


jacobjames
 Share

Recommended Posts

Hi all,

I have a game where I am 'faking' a camera rotation by changing the angle of the world. 

However,  my UI (although fixed to camera) is transforming with the world. My solution was to use a group for transformation instead (by putting everything that I need to rotate in a group called 'worldGroup'). This almost works perfectly, except that now the physics bodies (P2JS) are not transforming with the group/sprites, so my collisions are all over the place instead of staying with the sprites.

 

Does anyone have a solution for this? My only current solution is to learn how to make the UI on top of Phaser from CSS or something like that.

Any help is appreciated!


 

Link to comment
Share on other sites

Seems a little strange, but I'm guessing its because rotating the group is actually changing the positions of all the objects in that group, rather than just changing the visual position. If you see what I mean: the actual positions of things and the visual position (on screen) are different things (or they could be, I'm guessing they are the same here), the physics engine should be calculating based on actual position whilst the visual rendering portion could look differently.

I don't know how you'd achieve this with Phaser (I'd have tried doing what you're doing) but is there a way you can apply the 'camera' rotation before render and then unapply it for the update portion? I'm thinking out loud here, but would that solve the issue where physics (during update) would get the actual (untransformed) positions and then the render (during render) would get the applied transform?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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