Alwin Posted August 12, 2014 Share Posted August 12, 2014 Hi guys ! I am trying to create a classical 2D platform game (They are so great, aren't they?) with Phaser that i discovered recently. I certainly explain why i am not able to explain the reason of this strange behavior. My problem is that when i am moving my character, it only collides with the top and down sides of my blocks.Is there any reason for that behavior ? Here is my global configuration: // Physics configurationthis.phaserInstance.physics.startSystem(Phaser.Physics.ARCADE);this.phaserInstance.physics.arcade.gravity.y = 300;// Setting the world boundariesthis.phaserInstance.world.setBounds(0,0, 2800, 1400);// Adding the blue backgroundthis.phaserInstance.add.tileSprite(0,0, 2800 , 1400,'background');this.phaserInstance.camera.y = 1000;Then i add my sprites:box = this.phaserInstance.add.sprite(200, 1300, 'tiles', 'box');this.phaserInstance.physics.enable(box, Phaser.Physics.ARCADE);box.body.collideWorldBounds = true;box.body.allowGravity = false;box.body.immovable = true;me = this.phaserInstance.add.sprite(200, 1000, 'player1');this.phaserInstance.physics.enable(me, Phaser.Physics.ARCADE);me.body.collideWorldBounds = true;console.log(me.body.checkCollision.right);console.log(box.body.checkCollision.right);cursors = this.game.input.keyboard.createCursorKeys();Finally, i add my collision detection in the 'update' functionupdate: function(){ this.phaserInstance.physics.arcade.collide(me, box); if(cursors.right.isDown) { me.body.x += 5; } if(cursors.left.isDown) { me.body.x -= 5; }},Any thoughts ?Thanks ! Link to comment Share on other sites More sharing options...
lewster32 Posted August 12, 2014 Share Posted August 12, 2014 You shouldn't be changing the body.x directly, you should be using body.velocity.x otherwise the physics system will not know how to correctly apply the appropriate separation. See this example: http://gamemechanicexplorer.com/#platformer-1 Link to comment Share on other sites More sharing options...
Alwin Posted August 14, 2014 Author Share Posted August 14, 2014 Thanks for your answer.Its seems that managing the character with velocity.{x|y} instead of body.{x|y} fix my issue. Should i signal that problem on github ? Link to comment Share on other sites More sharing options...
ZoomBox Posted August 14, 2014 Share Posted August 14, 2014 Not at all because that's the way it's supposed to work.By setting the possition of the body, your are saying "go there but don't especially check for collision".By setting a velocity you are saying "Go this way and check collisions on the way". lewster32 1 Link to comment Share on other sites More sharing options...
Recommended Posts