Hello,
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)
move();
}
}
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?