Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PathFollower does not always end in the correct place #4950

Closed
bramp opened this issue Jan 10, 2020 · 3 comments
Closed

PathFollower does not always end in the correct place #4950

bramp opened this issue Jan 10, 2020 · 3 comments

Comments

@bramp
Copy link
Contributor

bramp commented Jan 10, 2020

Version

  • Phaser Version: 3.2.1
  • Operating system: MacOS
  • Browser: Chrome

Description

When using the PathFollower I found that short duration tweens did not end where I expected them. They feel short, for example, only reaching 90% of their target destination. Longer duration generally got nearer the target, but not the exact target.

Example Test Code

// Adapted from https://phaser.io/examples/v3/view/paths/followers/basic-follower

var config = {
    type: Phaser.AUTO,
    width: 640,
    height: 480,
    backgroundColor: '#2d2d2d',
    scene: {
        preload: preload,
        create: create
    }
};

var game = new Phaser.Game(config);

function preload ()
{
    this.load.image('ball', 'https://labs.phaser.io/assets/sprites/shinyball.png');
}

function create ()
{
    const text = this.add.text(30, 20, '', { font: '16px Courier', fill: '#00ff00' });
  
    const curve = new Phaser.Curves.Path(100, 100).lineTo(400, 400);
    var graphics = this.add.graphics();
    graphics.lineStyle(1, 0xffffff, 1);
    curve.draw(graphics, 64);
  
    const ball = this.add.follower(curve, 100, 100, 'ball');
    ball.startFollow({
      duration: 100,
      onComplete: function(tween, targets, param) {
        text.setText([
          'x: ' + ball.x, // Target is x: 400, y: 400
          'y: ' + ball.y,
        ]);
      }
    });
}

Full example on https://codepen.io/thebramp/pen/ExaLWyR

You'll see the ball does not hit 400x400, and depending on luck seems to hit various spots between 350 and 400.

Additional Information

Looking at the src/gameobjects/components/PathFollower.js pathUpdate() checks if the tween is PLAYING_FORWARD, and if not, it just returns. In my example, the last time pathUpdate is called where tween is PLAYING_FORWARD, the value returned by tween.getValue() is less than 1.0.

A suggested solution, is to allow pathUpdate() to do one final update after the tween transitions to COMPLETED. Thoughts?

@photonstorm
Copy link
Collaborator

Agreed, it should finish at the end of the path, regardless of the time left on the tween.

@bramp
Copy link
Contributor Author

bramp commented Jan 15, 2020

Great. I'm happy to send a PR to fix this, if you aren't already working on it.

@photonstorm
Copy link
Collaborator

Thank you for submitting this issue. We have fixed this and the fix has been pushed to the master branch. It will be part of the next release. If you get time to build and test it for yourself we would appreciate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants