Move spatial to a specific point

I am new to JMonkey and I am trying to do the simpliest thing in the world: to move a spatial from (0.0f, 0.0f, 0.0f) to

(0.0f, 0.0f, 1.0f) having a smooth movement. So I extend AbstractControl and I try something like this:

public class MyAbstractControl extends AbstractControl{
private Vector3f target;
private int direction;
private float tpf;

public void move(){
Vector3f start = spatial.getLocalTranslation();
spatial.setLocalTranslation(start.interpolate(target, tpf/start.distance(target)));
System.out.println("spatial.getLocalTranslation() = " + spatial.getLocalTranslation());

protected void controlUpdate(float tpf){
this.tpf = tpf;
if(spatial != null)

the problem is that the spatial doesn’t stay at (0.0f, 0.0f, 1.0f) but goes between (0.0, 0.0, 0.9992296) and (0.0, 0.0, 1.0024321) (the numbers are random each time) forever! What should I do? And what is the best way to do that?


you’ll need to add an if statement like

spatial.setLocalTranslation(start.interpolate(target, tpf/start.distance(target)));


because the object moves in increments according to tpf. itll never land on exactly 1.0f

yes, I ve seen this on an other post but I thought there was a more elegant way. I ll go with this solution. Thank you!