user3344581
user3344581

Reputation: 5

Gravity in 2d games(360 degrees)

Hello all I am trying to make a game with the Phaser game engine and would like to implement some sort of 360 gravity. Essentially I just want the player to be able to rotate around the sphere. I was wondering what would be the best way to do this in phaser. I know that you can set objects gravities but you can only do so in the x and y direction. Any help is greatly appreciated!

Upvotes: 0

Views: 406

Answers (1)

singhiskng
singhiskng

Reputation: 511

you should use the concept of vectors for this.

like you want as a planet attracts towards another sun in a orbit.

then define
function Vector(x, y){ this.x = x || 0; this.y = y || 0; }

and these are pseudo codes
get acceleration vector direction by
vector(sun.position.x-planet.position.x,sun.position.y-planet.position.y)

then
planet.velocity.x+=acceleration.x planet.velocity.y+=acceleration.y

for further using vector you can try http://www.metanetsoftware.com/technique/tutorialA.html

Upvotes: 1

Related Questions