Sign in to follow this  

Physics Bodies Not Moving With Sprite Group

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!


Share this post

Link to post
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?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.