# Orbiting problem

## Recommended Posts

Hello!

Can someone tell me why is this happenening?

As you can see the visual body is in a different place as the physical body.

##### Share on other sites

I believe there's currently an issue with pivots in pixi.js (Phaser's underlying rendering engine) that is causing problems with the position of the body. I had a similar issue and had to abandon rotation of the sprite, instead resorting to extending the sprite and rotating a child image instead.

##### Share on other sites

Thanks for the answer! Can you please tell how did you do it?

##### Share on other sites

To be fair my solution wouldn't be the right solution in your case, as presumably you need an orbiting mechanic and the ability to detect collisions on that orbiting item. In your case I may do something like this:

`// Create our solar system groupvar solarSystem = game.add.group();// Create our sun and use the group's 0, 0 position as the center of the solar systemvar sun = game.add.sprite(0, 0, 'sun', 0, solarSystem);// Set the sun's anchor to 0.5, 0.5 so it is completely centeredsun.anchor.set(0.5);// Create a group to manage the orbit of our planet, and place it inside the solar systemvar planet1Orbit = game.add.group(solarSystem);// Create our planet and place it off-centre by 50 pixelsvar planet1 = game.add.sprite(50, 0, 'planet', 0, planet1Orbit);// Also set the planet's anchor to 0.5 so we don't get any weird offsetsplanet1.anchor.set(0.5);// Finally add a body to the planet so we can detect collisionsgame.physics.enable(planet1, Phaser.Physics.ARCADE);// And now the magic part - rotate the planet1Orbit group instead of the planetfunction update() {  planet1Orbit.angle += 1;  // you can also make the planet spin separately  planet1.angle += 2;  // or you could make it spin in the opposite direction at the same rate, and the planet will appear to move around the sun without rotating itself  // planet.angle -= 1;}`

This is a very simple way to get an orbit-like mechanic just by using groups. Because the scene graph allows objects to be placed inside other objects and inherit their transforms, you end up with the same effect. It does however have limitations - you will only be able to create circular orbits with this method; if you want to create more advanced orbits you'll have to do it with carefully balanced physics and maths.

##### Share on other sites

Thank you for the answer, it works that way!