Jump to content

sprite deceleration


Recommended Posts



I want to have a sprite (laser) decelerate from its original position (cannon) to its destination (current pointer position on click).

I tried negative values with accelerateToPointer :

game.physics.accelerateToPointer(laser, this.game.input.activePointer, -600, 100, 100);

but the behavior isn't the one I expected since the sprite goes immediatly backward.


So I tried to play with body.acceleration instead :

laser.body.velocity.x = 500;laser.body.velocity.y = 500;laser.body.acceleration.x = -500;laser.body.acceleration.y = -500;

The behavior is far more better (the sprite slows down til a certain point, but then goes backward), but I couldn't find how to set the minVelocity for the sprite to decelerate.

Whether I use body.maxVelocity or nothing, it finally goes backward (negative speed, I guess).


Is there a way to set this minVelocity for negative accelerations or need I just to test by myself the velocity in the update loop ?


Link to comment
Share on other sites

function fireLaser() {  laser = lasers.getFirstExists(false);  if (laser) {    laser.reset(80,20, 1);    laser.outOfBoundsKill = true;    //laser.rotation = game.physics.accelerateToPointer(laser);    laser.body.velocity.x = 800;    laser.body.velocity.y = 800;    laser.body.drag.x = 50;    laser.body.drag.y = 50;    }  }}

Still no deceleration effect, although there's no acceleration set


prototype here : http://jerome.bousquie.fr/phaser/game1/


but please don't mind, I'll compute the decreasing velocity

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...