Move vector toward another vector

Hi there.

Im making a simple pathfinding algo and i got confused in its first part, how could i move a vector toward another vector in a constant speed ??

THanks alot for any attention !

[jME Tutorial 1-2] Vector math with the jMonkeyEngine - YouTube

Basically subtract the initial vector from the destination vector, and normalize it. This gives you the direction, and then do vec1.move(direction.mult(tpf)) or w/e


And please do go through this

i dont got how could i use interpolation to do this


private static final float moveSpeed = 1f;

public void moveTowards(Vector3f dir) {




How could i use interpolation to get a vector to the direction however at a constant movespeed ?

You also have to multiply the movespeed with tpf to have a constant movespeed since the speed basically right now depends on your framerate…

i do that was an example code ^^

thanks for the attention, but , i couldnt do my intention yet :frowning:

ty for the help

You can also do firstVector.subtract(otherVector) and then you get a new Vector that points from otherVector to secondVector.

You basically do the things above, that means you subtract your goal vector from your current position vector and then you NORMALIZE it. Only then you can make sure that it will say “the same length” in every situation. And then you just multiply your normalized direction vector with movespeedtpf and you’re fine! :slight_smile:

public void moveTowards(Vector3f dir) {



Remember that directions are always normalized!

1 Like

aaah now i understand what normalize do ;d

thank you alot !

all of this was said in the first reply :stuck_out_tongue:

@wezrule said:
all of this was said in the first reply :P