Jump to content

Why thrust is not working?


ekeimaja
 Share

Recommended Posts

    create: function () {        this.game.world.setBounds(0, 0, 1920, 120);        this.game.physics.startSystem(Phaser.Physics.P2JS);        this.game.physics.p2.defaultRestitution = 0.8;        this.player = this.game.add.sprite(100, 100, 'player_spr');        this.game.physics.p2.enable(this.player);        this.game.camera.follow(this.player);        this.cursors = this.game.input.keyboard.createCursorKeys();    },    update: function () {            if (this.cursors.right.isDown)            {                this.player.body.thrust(400);            }            else if (this.cursors.left.isDown)            {                this.player.body.reverse(400);            }            }

This code is based on tutorial code, so it should be right.  But it is not working at all.

Link to comment
Share on other sites

I dont know how Phaser implements things, but, dont you need some sort of `this.player.update()` or a world update?

 

p2 normally has a piece of code (like this) that steps the world simulation forward.

 

It is necessary because you are applying forces and the simulation then translates those forces into momentum, which, in turn, moves your stuff around. Stuff like collision detection normally happens in the simulation step (or update) function as well.

 

edit: oh, I just saw the `this.game.physics.startSystem(Phaser.Physics.P2JS)` which I guess handles starting off that simulation step loop.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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