Jump to content

Gravity Issue/Help? [2.0.1]


Heppell08
 Share

Recommended Posts

So in my game im setting the gravity to a value of 800. When i console log the gravity its telling me the gravity value is -40!

Then when i set it to 400 the value was -27 and then at 100 the value was -5!

 

Is there something im doing wrong here:

 

        this.physics.startSystem(Phaser.Physics.P2JS);        this.physics.p2.gravity.y = 800;        this.createMap();        player = this.add.sprite(currentLevelX, currentLevelY, 'player01');        player.animations.add('walk',[0,1,2,3,4,5], 4, true);        player.anchor.setTo(0.5, 0.5);        player.alpha = 0;        player.scale.x = 1.5;        player.scale.y = 1.5;        this.physics.p2.enable(player);         player.body.data.gravityScale = 1;

Thats the create and setting of all the physics in my create. There is no more physics related code other than setting the tilemap which is this:

this.physics.p2.convertTilemap(map, layer);
Link to comment
Share on other sites

This is correct. All values in p2 (and most physics systems) operate in meters, and also in the opposite of screen space. In order to make this less frustrating for you we allow you to set speeds and distances in pixels rather than meters. Which means every time you set a value we have to translate it. Most values are re-translated from p2 back to pixels again on display, but not all (some it just doesn't make sense as they are setters, like gravity).

Link to comment
Share on other sites

So what i would do (and have if im right) is set it like this:

this.physics.p2.gravity.y = 1000 * 10;

so i get a return value of -500?

 

Its all very different. Just looking at the tilemap gravity example im using the same in my game seems to return a lot of different values and gameplay mechanics. Like jumping for example. 

Do i set the value in my players jump for moveUp() to a value of space i want it to move or do i set velocity for, well velocity up lol.

Been fiddling in 2.0.1 and these pixel/meter movement stuff is all very new being a 1.1.5 lover of phaser.

Link to comment
Share on other sites

No everything is still the same way around as before, because Phaser handles all of the axis translation for you.

 

The values given to moveUp() etc are given in pixels per second. So if you want your sprite to move 100 pixels in 1 second, give it a value of 100.

 

You don't need to actually modify any of your values prior to giving them to P2, you just need to be aware that under the hood that is what is happening.

Link to comment
Share on other sites

So is there a specific reason why my player very slowly falls to the floor with 500 gravity yet jumping is like an instant oomph of velocity?

I tested the same values you did in the tilemap gravity and get nowhere close to the same results and style of play.

Is using states having an effect or am I missing something out?

Would uploading the game with no ugly code in dropbox maybe even worth a go so you can see what's wrong?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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