Heppell08 Posted March 25, 2014 Share Posted March 25, 2014 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 More sharing options...
rich Posted March 25, 2014 Share Posted March 25, 2014 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 More sharing options...
Heppell08 Posted March 25, 2014 Author Share Posted March 25, 2014 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 More sharing options...
Heppell08 Posted March 25, 2014 Author Share Posted March 25, 2014 So after a bit of thinking am i right in presuming that y<0 is now opposite to what we normally assume? Is 0,0 bottom right and not top left now? I can work around them in that sense if im right in thinking what i think im thinking... Link to comment Share on other sites More sharing options...
rich Posted March 25, 2014 Share Posted March 25, 2014 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 More sharing options...
Heppell08 Posted March 25, 2014 Author Share Posted March 25, 2014 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 More sharing options...
rich Posted March 25, 2014 Share Posted March 25, 2014 Do you set velocity to zero in the update loop? If so that is probably cancelling out the gravity. Remember the update loop is applied AFTER the physics step has occurred. Link to comment Share on other sites More sharing options...
Heppell08 Posted March 25, 2014 Author Share Posted March 25, 2014 I use the setZeroVelocity(); call I've seen. I'll remove it now and see! Hopefully this fixes it then I hope. Link to comment Share on other sites More sharing options...
Heppell08 Posted March 25, 2014 Author Share Posted March 25, 2014 Yeah the velocity to 0 fixed it!! Got the desired results i wanted. Seem like i can now get this updated into 2.0.1 now. Luckily 99% of it is done, just need to work in the physics but thanks!! All up and running now. Link to comment Share on other sites More sharing options...
Recommended Posts