# Circular World...?!

## Recommended Posts

Hi everybody !

I like so much PHASER but it brings to me some probs ! ^^

I'm making a game, with a circular world, and i need to make appear some stars, they have to move relative to the center of the game's world and i really don't know how can i do this ?

Thank you !

And sorry again about my english !

##### Share on other sites

You can't use P2 + Arcade physics together (and if it was possible, you shouldn't).

You should work on you own gravity thing in order to achieve that.

I imagine you have a "earth" sprite and the center of it is the center of gravity.

You should enable one of these two physic engine (I recommand P2 because it has always been more reliant and with more capabilities from my point of view). Only enable physics but not gravity.

Then, for each of your physical object you should have a "fall()" function which would calculate the angle between him and the center of the earth and rotate it + push it toward, following the vector you just calculated. Since physic is enabled, is should just hit the ground and not go thourgh.

In order to calculate the velocity you should apply to your objects' bodies you can try simple calculations like this: body.velocity *= 1.01 or something like this.

tl;dr:

• Enable physics but not gravity
• Get an angle between your object and the center of your planet
• Rotate the object following this angle
• Push the object toward the center of your planet (apply you own "gravity" thing)

Tips:

There is maybe a "body.face(point);" function in P2.

There is maybe a "body.pushToward(point);" function un P2.

=> I quickly checked P2 docs and I couldn't find anything like those two ideas.

Edit: Salut Français, j'en suis un aussi.

##### Share on other sites

Outch....

this seem too hard for me ...

Thank a lot !

##### Share on other sites

An other way :

Can i create a group place at the center of my earth, coins into the group, and i rotate the group ?

`pieces = game.add.group(game.width/2,game.height*1.8,'piecesGroup');piece = pieces.create(400,120,"piece");pieces.angle -= 1;`

???

##### Share on other sites

It's actually quite simple !

• http://docs.phaser.io/Phaser.Point.html#angle (get an angle between two points)
• player.body.angle = myAngle; (To rotate the player following this angle. I would personnaly not use this, maybe more rotateLeft() and rotateRight() but for test purpose it should be OK)
• Now, since you can only set velocity on a body (to move it) with x and y, you have to use some trigonometry rules (ouch !). I could only explain it with a simple drawing but I'm at work => From this angle + the distance between you player and the planet, you have a right-angled triangle ("triangle rectangle") and the distance planet-to-player is the hypotenuse. So, with some easy calculation (sin, cor or tan ?) you can calculate the two other sides of the triangle.
• Those two sides are your x and y velocity needed to make the player/object move toward the planet.

I'll maybe try this during my midday pause.

##### Share on other sites

I don't understand what you said in your previous post (about groups). Could you explain ?

##### Share on other sites

Thank you ! I know trigonometry ^^

And i understand all that u say !

But, in my case, P2 is really useless because i need a short time dev and my hero don't move in game

I find a good way !

`piece = pieces.create(650,1700,"piece");piece.anchor.setTo(0.5,0.5);piece.pivot.x = game.width/2;piece.pivot.y = game.height*1.8;piece.angle +=0.5;`

With that, my coin revolve around my earth !!!

Nom i've to do the same, but with a group to put in many coins !