Move car by waypoints array list

I want my car to drive by a vector list. When I use setLocalTranslation and print the position of the agv the good positions are printed but the car doesn’t move. When I use move the positions are getting extremely high values in a short amount of time.

Output with agv.move(waypoints)

Agv loc  (560.0, 9.5, -1500.0)
Agv loc  (1120.0, 19.0, -30.0)
Agv loc  (560.0, 28.5, 1440.0)
Agv loc  (0.0, 38.0, -120.0)
Agv loc  (560.0, 47.5, -1680.0)
Agv loc  (1120.0, 57.0, -3180.0)
Agv loc  (1680.0, 66.5, -4680.0)
Agv loc  (2240.0, 76.0, -3210.0)
Agv loc  (1680.0, 85.5, -1740.0)
Agv loc  (1120.0, 95.0, -3300.0)
Agv loc  (1680.0, 104.5, -4860.0)
Agv loc  (2240.0, 114.0, -6360.0)
Agv loc  (2800.0, 123.5, -7860.0)
Agv loc  (3360.0, 133.0, -6390.0)

The drive method:

public void drive(AssetManager assetManager, Node rootNode, Node guiNode,FlyByCamera flyCam,final Camera cam){
        parkingleft = new Vector3f (560,7,1465);
        waypoints.add(new Vector3f(560,9.5f,-1500));
        waypoints.add(new Vector3f(560,9.5f,1470));
        waypoints.add(new Vector3f(-560,9.5f,1470));
        waypoints.add(new Vector3f(-560,9.5f,-1560));
        waypoints.add(new Vector3f(560,9.5f,-1560));
        waypoints.add(new Vector3f(560,9.5f,-1500));

        System.out.println("Content waypoints arraylist: "  + waypoints);


Update agv position method

public void updateAgvPosition(float tpf){
       for(Vector3f waypoint : waypoints){
     //  agv.move(waypoint);
       System.out.println("Agv loc  "+ agv.getLocalTranslation());

Main code


public void simpleUpdate(float tpf) {


// the drive method is called in simpleinitapp


How to move the car by my vector list?


Main code

 public void simpleUpdate(float tpf) {

// drive method called in simple init app

Do you actually want to see the car move from point to point or teleport instantly? setLocalTranslation() as you use it currently warps the car to the location relative to the node it’s attached to , there is no interpolation in between. Also, you are setting the local translation in a for loop, which blocks the render thread, so you wouldn’t see any “movement” anyways, you would only see the car in the location of the last waypoint in your list.

I want to see the car moving from point to point. How to go through the list with vectors and move the car along the vectors in my list in a way I can see the car moving?

You probably want to interpolate between the waypoints using something like com.jme3.math.Vector3f.interpolate(Vector3f, Vector3f, float).

For instance, if the waypoints were 1 time-unit apart, you would add “update” code to change the car’s location to
interpolate(waypoint[(int)time], waypoint[1+(int)time], time%1).

For a smoother ride, you might want to update the car’s orientation as welll and/or use a higher-order interpolation such as splines.

As far as I am aware, using waypoints will only move the spatial, not the vehicle, so you’re going to end up in trouble. Use debug mode to confirm.

Try this: Get the direction by subtracting position B from position A, and normalize the distance of the points to use as a multiplier for the speed of the vehicle.

I think you mean somenthing like this. How do I substract vector b from vector a ( I need to get the vectors from the list)? How do get the vector at i and i++ and substract them? Also do I need the for loop or is this unessential?

       for(Vector3f waypoint : waypoints){
           Vector3f distanceAB;
           distanceAB = ?

       System.out.println("Agv loc  "+ agv.getLocalTranslation());

Take a look at the Motionpaths, they might be what you want. (There is something in the examples)

I already tried but it doesn’t work for what I want so i’m using a vector list now.

To subtract one Vector3f from another use a.subtract(b);

The two vectors in question are the current vehicle location (note that you need to get the vehicle location from vehicleControl.getPhysicsLocation()) and the first item in the list (which is the next waypoint). I would just check the current location of the vehicle with the first location in the list to see if they match. If they do, remove it from the list. Rinse and repeat until the list is empty. That way you are only checking the first item in the list and not iterating over them all, and also not causing any confusion over potential overlaps or close positioning.

An ArrayDeque would probably be more fitting than an ArrayList - it’s quicker at removing items from either end.