# [Solved] Move node constant speed in a grid

Hello,
I need to move a node in a grid, you can only move to an adjacent cell, currently my logic is as follows:

if (! Node.getLocalTranslation (). equals (nodeNewPosition)) {

Node.setLocalTranslation (nodeNewPosition);

}

Obviously when you run the application, my node jumps between cells, I need to improve it so that it moves at a constant speed between cell and cell, any ideas ?.

I’ve seen “Move Object with constant speed?” where it seems they solved but I do not work for me.

regards

That actually is a basic vector geometry stuff.
Considering you wan’t to move from A to B with speed X, the direction vector C would be B - A, then you normalize C (making it a vector with length of 1) and multiply it by X.
So something like D = B.substract(a).normalize().mult(X);
And then you set your node translation to A + D

In your case you will actually have to check if the result vector’s, say, D’s, length is greater than distance between B and A, and if it’s true then you just set the node translation to B

Hi,
Thanks!,the final logic is:

``````				Vector3f a = from
Vector3f b = to;
Vector3f c = b.subtract(a);
float x = 5f;
Vector3f d = c.normalize().mult(x*tpf);
if(d.length()>a.distance(b)){
d = c;
}