Jump to content

sprite deceleration


jerome
 Share

Recommended Posts

Hi,

 

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

laser.body.velocity.x = 800;laser.body.velocity.y = 800;laser.body.drag.x = 800;laser.body.drag.y = 800;

no effect at all :(   (no slow down)

Am I doing it wrong ?

Maybe is it worth I compute decreasing velocity in my code ...

Link to comment
Share on other sites

Currently drag is only applied if there's no acceleration set, also the drag value you've got there is really high. Make sure you've no acceleration set and set drag to something smaller (try 100 to start with) and see if that effects velocity the way you'd expect.

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

 Share

  • Recently Browsing   0 members

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