Inconsistent speed across MotionPath when using varying length Waypoints


I am having a small issue with MotionPath and MotionEvent when creating a cinematic. I’ve found that when I am using waypoints which are placed at varying distances(different segment lengths), the camera moves at an inconsistent speed between different waypoints.

I have found that the shorter the segment length, the quicker the camera moves. As far as I can tell this seems to be something to do with the way that currentValue is calculated by the getWayPointIndexForDistance Method in MotionPath (currentValue increases considerably quicker for the shorter waypoints).

I was just wondering if 1) anyone else had had a similar issue before and how they managed to solve it. If not then what I am going to do is try and create an alternate method to calculate distance - in this case 2) is there an easy way to create local copies of libraries so that they can be edited - and is this a terrible idea?

I would like to note that I have checked the forum and found a similar problem which talks about setting curve tension but this seems to be unrelated.

I’ve attached a basic example which should show you what I mean:

private MotionEvent event;
private MotionPath path;

public void simpleInitApp() {
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    path = new MotionPath();

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);

    ChaseCamera chaseCam = new ChaseCamera(cam, geom, inputManager);
    path.addWayPoint(new Vector3f(1, 1, 0 ));
    path.addWayPoint(new Vector3f(1, 1, 50 ));
    path.addWayPoint(new Vector3f(1, 1, 60 ));
    path.addWayPoint(new Vector3f(1, 1, 70 ));
    path.addWayPoint(new Vector3f(1, 1, 80 ));
    path.addWayPoint(new Vector3f(1, 1, 110 ));
    path.addWayPoint(new Vector3f(1, 1, 150 ));
    path.addWayPoint(new Vector3f(1, 1, 250 ));
    path.enableDebugShape(assetManager, rootNode);
    event = new MotionEvent(geom, path);



When it reaches to a turn the speed is decreased until pass the turn but i am not sure if this also happens with different distances.
But you can set path.setPathSplineType(Spline.SplineType.Linear); to have fixed speed all over the path.

Many thanks for your help, I’ve just had a chance to test that out and it works for linear paths, and I found I had a constant speed all over.

However ideally I would like a path that keeps the curve while maintaining a constant speed - for a better example a path of this size. If I was constructing the path I using a linear spline I would get a rectangle rather than a oval.

    path.addWayPoint(new Vector3f(0, 1, 0 ));
    path.addWayPoint(new Vector3f(20, 1, 0 ));
    path.addWayPoint(new Vector3f(20, 1, 40 ));
    path.addWayPoint(new Vector3f(0, 1, 40 ));

Is there any way to have a curved path and a constant speed so that the event does not slow down for corners?


Have not tested it really, you may try other SplineType . You can also take a look at source code and javadoc for this.
Maybe @coredevelopers can better help with this.

I’ve tried the other spline types as well but Catmull gives the same issue (it seems to be the default). And the other two, Nurb and Bezier, didn’t work as the curves generated do not intersect with the waypoints.

Thanks for you help anyway, I will have a play around and see what I can do.