0

I've build a MotionPath for my Spatial by adding waypoints. It is working fine when I do something like this

path.addWayPoint(new Vector3f(0, 0, 0));
path.addWayPoint(new Vector3f(2, 0, 0));
path.addWayPoint(new Vector3f(4, 0, 0));
path.addWayPoint(new Vector3f(6, 0, 0));

I wanted to move it dynamicly by putting waypoints in method like this

public void moveSpatial(float x) {
    Vector3f currentTranslation = spatial.getLocalTranslation();
    path.addWayPoint(currentTranslation.x, 0, 0);
    path.addWayPoint(currentTranslation.x + x, 0, 0);
}

and in simpleUpdate method I've added

spatial.setLocalTranslation(new Vector3f(newX, 0, 0);

where

float newX = currentTranslation.x + x;

now, the animation (smooth move) is working BUT every time when I invoke moveSpatial method the spatial first goes to starting point Vector3f(0, 0, 0) and then he is moving by waypoints. the (0, 0, 0) is position set for spatial when I start the application. I would like to make the movement from the last position where spatial ended his movement. How to do this ?

Fixus
  • 4,631
  • 10
  • 38
  • 67
  • i guess this is related to your other question at http://stackoverflow.com/questions/30479970/smooth-translation-combined-with-compas ? i think this is an odd approach to your problem. i'll try to contribute something to the original post instead. – 1000ml May 31 '15 at 07:13

1 Answers1

0

I found the solution and it is really simple :) To prevent this strange behaviour there is a need to add in waypoint listener change of localTranslation. Than when the new waypoint will be added from last current position it will start where it ended

Fixus
  • 4,631
  • 10
  • 38
  • 67