# Help the Newb: Gravity along the x-axis

## Recommended Posts

JELLO!

First post.  New to forum.  If this is not the right place or way to get help, please let me know and I will take my ignorance elsewhere!

Background: I'm creating a physic game revolving around the manipulating of gravity by the player character in a platformer-style world.

Desired Result: Be able to change the gravity so that the character "falls" down, or up, or left, or right.

Attempt: Down and up is fine (.physics.gravity.y = 100 or .physics.gravity.y = -100) so tried to accomplish left and right by .physics.gravity.x = 100 and .physics.gravity.x = -100.  But the character did not "fall" left and right as I had hoped.

How would I accomplish the effect of make the world's gravity shifting in the four directions.  So that if, say, I hit a key that made the gravity shift to the right the character would suddenly start "falling" left?

Thanks!  Loving Phaser thus far!

##### Share on other sites

Can you please share a piece of code? I think I have the same problem. Do you need to define the Physics somewhere to use them as property in 1.1.5?

I have this and the player won't fall down. The same code works fine with older versions.

this.player.body.gravity.y = 10;

Hope someone can clear this matter.

EDIT: Setting a higher value for gravity, for example 200, works.

this.player.body.gravity.y = 10;
##### Share on other sites

• 11 months later...

Bumping because I'm trying to do the same thing and this looks unanswered.

Trying to get x-axis or horizontal gravity working. Have y-axis gravity working fine as expected. But setting sprite.body.velocity.x to same value as y doesn't result in the same velocity of gravity. Sprite moves very slowly in one direction, not indicative of a 'falling' effect.

Some test code:

function create() {

sprite.body.gravity.y = 0;

sprite.body.gravity.x = 300;