Hi,
I am using the update method from AutonomousVehicleControl for a vehicle movement using the following code:
[java]
private Vector3f vector1 = new Vector3f();
private Vector3f vector2 = new Vector3f();
private Vector3f vector3 = new Vector3f();//valideLocations[3];
private Vector3f vector4 = new Vector3f();//valideLocations[4];
static final Quaternion ROTATE_RIGHT = new Quaternion().fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y);
private Plane plane = new Plane();
private float speed = -800f;
Spatial map;
public void CarMoveAt(Vector3f targetLocation) {
vehicle.getPhysicsLocation(vector1);
vector2.set(targetLocation);
vector2.subtractLocal(vector1);
float distance = vector2.length();
float checkRadius = 4;
if (distance <= checkRadius) {
//moving = false;
vehicle.accelerate(0);
vehicle.brake(10);
} else {
vector2.set(targetLocation);
vector2.normalizeLocal();
vehicle.getForwardVector(vector3);
vector4.set(vector3);
ROTATE_RIGHT.multLocal(vector4);
plane.setOriginNormal(map.getWorldTranslation(), vector4);
float dot = 1 - vector3.dot(vector2);
float angle = vector3.angleBetween(vector2);
float anglemult = FastMath.PI / 4.0f;
float speedmult = 0.3f;//0.3f;
if (angle > FastMath.QUARTER_PI) {
angle = FastMath.QUARTER_PI;
}
//left or right
if (plane.whichSide(targetLocation) == Plane.Side.Negative) {
anglemult *= -1;
}
//backwards
if (dot > 1) {
speedmult *= -1;
anglemult *= -1;
}
vehicle.steer(angle * anglemult);
vehicle.accelerate(-speed * speedmult);
vehicle.brake(0);
}
}
[/java]
I have seen just one post on this problem at Move vehicle towards a point, tried to run the solution, but with no succes.
The problem is the same, at some point, after some steering to the direction idk why the method to decide if the target is right or left side to the plane normal is changing values alternatively, causing the car to steer in zig-zag and lose control of direction.