What am I missing about using a set velocity?

Hello,

It seems to me that setting a sprite to a set velocity actually sets a lower amount, then sets it higher after a duration. See the following code:

import Phaser from "phaser";

const config = {
  type: Phaser.AUTO,
  width: 800,
  height: 600,
  backgroundColor: "#000",
  parent: "game-container",
  pixelArt: true,
  scene: {
    preload: preload,
    create: create
  },
  physics: {
    default: "arcade",
    arcade: {
      debug: true
    }
  }
};

const game = new Phaser.Game(config);

function preload() {
  this.load.image('cursor', '../assets/images/crosshair.png');
  this.load.image("player", "../assets/images/player.png");
}

function create() {

  this.calculateDegreesFromRadian = (radian) => {
    return radian * 180 / Math.PI;
  }

  this.calculateAngleInDegrees = (x, y, x2, y2) => {
    return this.calculateDegreesFromRadian(Phaser.Math.Angle.Between(x, y, x2, y2));
  }

  this.player = this.physics.add.image(20, 20, "player", 0);
  this.cursor = this.add.image(0, 0, 'cursor').setVisible(true);

  this.input.on('pointermove', function (pointer) {

    this.cursor.setPosition(pointer.x, pointer.y);
    this.physics.velocityFromAngle(this.calculateAngleInDegrees(this.player.x, this.player.y, this.cursor.x, this.cursor.y), 100, this.player.body.velocity);

  }, this);

}

Which produces the following: https://gyazo.com/8444a740545136c0029588c87396655b

Why does the sprite speed up after a time? It seems to do this even if i am just statically setting a X or Y velocity with no calculations as to the cursor.

Thanks

I have tested it several times and it works perfectly. The speed remains always the same.

Could it be that at the beginning of the video you have a really low frame rate? I have no idea what else it could be.

Well, the frame rate is a pretty steady 29/30fps according to dev tools. Thanks for the response though. It seems like the main game loop chugs for a few seconds every time I tab in / out of the tab it does that.

I have a pretty strong machine & network, I’m not really sure what could be causing the problem.

The only thing that could impact the performance are 3 properties in your config file: type, pixelArt and debug. I do not believe one of them causes such a high frame drop.

Or do you use a online editor?

Hope you will figure it out :slight_smile:

If you go to this fiddle, does it do it: https://jsfiddle.net/bqc2jzto/1/

For me it behaves the same as the gif i linked. @yannick

It works perfectly on my phone.

It does look like FPS issue. Phaser smooths out delta time, so if you suddenly get smaller deltas (higher FPS) then for a short while you would get faster movement as the delta is smoothed based on previous values (i.e. real is smaller than applied).
You could check for that by logging both Phaser’s delta time and actual delta time.