# Travelling curves not constant

Hi.
I’ve written a simple example code that is supposed to move an object along a curve/spline. The problem is that the travel speed is not constant, although the step distances are.

Here is a example of what I mean: [java]
package jme3test.helloworld;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Quaternion;
import com.jme3.math.Spline;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.scene.shape.Curve;

public class CurveTraveller extends SimpleApplication {

``````public Geometry box;
public Spline spline;
public float totalDistanceToTravel;
public float distanceTraveledThisSegment = 0;
public float distanceTraveledTotal = 0;
public int currentControlPoint = 0;
public float debugTime = 0;

public static void main(String[] args) {
final CurveTraveller app = new CurveTraveller();
app.start();
}

@Override
public void simpleInitApp() {
HudDebugger.create(guiNode, guiFont);
HudDebugger.getInstance().display();

viewPort.setBackgroundColor(ColorRGBA.DarkGray);

Box box = new Box(0.3f, 0.3f, 0.3f);
this.box = new Geometry("box", box);

rootNode.attachChild(this.box);

Vector3f cp1 = new Vector3f(0, -10, 0);
Vector3f cp2 = new Vector3f(4, -10, 0);
Vector3f cp3 = new Vector3f(6, -10, 6);
Vector3f cp4 = new Vector3f(10, -10, 6);
Vector3f cp5 = new Vector3f(5, -10, 10);

Vector3f[] controlPoints = {cp1, cp2, cp3, cp4, cp5};
spline = new Spline(Spline.SplineType.CatmullRom, controlPoints, 1, false);

Curve curve = new Curve(spline, 10);
Geometry curveGeometry = new Geometry("curve", curve);
rootNode.attachChild(curveGeometry);

totalDistanceToTravel = spline.getTotalLength();

}

@Override
public void simpleUpdate(float tpf) {
HudDebugger hudDebugger = HudDebugger.getInstance();

if (distanceTraveledTotal  currentSegmentLength) {
distanceTraveledThisSegment = 0;
currentControlPoint += 1;
}

distanceTraveledTotal += distanceThisFrame;

cam.lookAt(box.getLocalTranslation(), Vector3f.UNIT_Y);
}

}
``````

}[/java]

It looks like that the interpolation is not based on the true spline length, instead it’s subdivided subsegments. I dont think this is a correct behaviour.

1 Like