Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Help the Newb: Gravity along the x-axis


lt3be
 Share

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! :D

Link to comment
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;
Link to comment
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;

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...