Need a Equation to fix My animation problem :/

1st Post!

Problem is the farther the xx is from player.layoutXProperty()…etc the faster the player moves, cause he is set to go from point A to point B in 1500ms…any ideas?

Thanks!

@Override
public void handle(MouseEvent m) {
double xx = m.getSceneX();
double yy = m.getSceneY();

            Timeline t = new Timeline();
            KeyValue kvX = new KeyValue(player.layoutXProperty(), xx);
            KeyValue kvY = new KeyValue(player.layoutYProperty(), yy);
            KeyFrame kfX = new KeyFrame(Duration.millis(1500), kvX);
            KeyFrame kfY = new KeyFrame(Duration.millis(1500), kvY);
            t.getKeyFrames().addAll(kfX, kfY);
            t.play();

Either:

  • Calculate the angle, then move the player by using sin() and cos()
  • Put a cap on the movement

Fixed it, had to divide the total distance it is going to move by 10, and make it a “x” amount of time to get to each segment, that kept it at a steady speed. Just in case anyone was wondering :clue: