"Spatial" moves to Vector3f

i really didnt find any method that i could use to do this…

i have an Spatial Object…

how i would make him move alone (without keyboard or mouse clicks)…

to a Vector3f that i choose?

Y will be always 0… as the terrain is plain…

if he is in  X,Z  10,10…

i want he moves to 20,30 for example…

i tried to make with x+=speed and z+=speed… until it reachs the target…

but i dont think this is the right way to do…

should i find an "angle" and use the right vector to moves in the direction?

there is a way to just let the object moves Forward ? (from his own Direction)

i dont need any pathfinding algoritm, cause the path will be always "free"…

Thanks :slight_smile:

Vector3f has an interpolate method that you can use by changing the last parameter from 0 to 1 in a smooth way over time. You can also use the lookAt method in Node to orient your objects.

I also have question just for the matter of understanding because I see that it works, but I don't know why it works:

if(initMovement == true)




"geo_coord": this is the coordinates/centerpoint of the object I click with the mouse

"intersectionpoint": this is the coordinates where the mouseray intersects with the terrain

Though this interpolation works like a charm, and the Object moves smoothly I don't know why this is the case. I would have expected something like that: Geometry.interpolate(Startpoint,TargetPoint,Speed). So how does the interpolate-function knows that an Object "belongs" to the Coordinates and which Object belongs to the Vector3f?

if you want to move sth. to a vector, I would use a controller

sth. like this is in the updade method:

            Quaternion oldRot = new Quaternion(me.getLocalRotation());

           // look in the right direction
            me.lookAt(TargetVector, Vector3f.UNIT_Y);
            // move towards the target
            Quaternion newRot = new Quaternion(me.getLocalRotation());
            me.getLocalRotation().slerp(newRot, agility*time);
            //change y position according to terrain page
            if(terrainPage!=null) me.getLocalTranslation().y = terrainPage.getHeight(me.getWorldTranslation())-20;

Thx, that helped a lot and worked!

I have another quick question: When I use spatial.lookAt(targetVector), how can I determine which side of the object shall face the target? e.g. a rectangular box always faces with the same side the targetVector. But what if I want to change this object into a playermodel? => then probably the back of the playermodel would face the target. I tried to change the localrotation but whenever it comes to "lookAt()" the side of the object always changes back to its usual direction :confused:

You will need to use the Quaternion lookAt method directly and invert the direction using Vector3f.negate so that you get a "lookFrom" behavior.  The Spatial.lookAt method takes a world position instead of a direction, so to get same behavior the code would look something like this:

Quaternion q = new Quaternion();
// If target vector is a world position then do this:
// otherwise if it is a direction we can skip the above line and do this instead