Jump to content

Why thrust is not working?


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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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