When attaching AI to a vehicle should I define all steps or try Line of Sight?
- by ThorDivDev
This problem is related to an intersection simulation I am building for university. I will try to make it as general as possible.
I am trying to assign AI to a vehicle using the JMonkeyEngine platform. AIGama_JmonkeyEngine explains that if you wish to create a car that follows a path you can define the path in steps. If there was no physics attached whatsoever then all you need to do is define the x,y,z values of where you want the object to appear in all subsequent steps. I am attaching the vehicleControl that implements jBullet. In this case the author mentions that I would need to define the steering and accelerating behaviors at each step.
I was trying to use ghost controls that represented waypoints and when on colliding the car would decide what to do next like stopping at a red light. This didn't work so well. Car doesn't face right.
public void update(float tpf) {
Vector3f currentPos = aiVehicle.getPhysicsLocation();
Vector3f baseforwardVector = currentPos.clone();
Vector3f forwardVector;
Vector3f subsVector;
if (currentState == ObjectState.Running) {
aiVehicle.accelerate(-800);
} else if (currentState == ObjectState.Seeking) {
baseforwardVector = baseforwardVector.normalize();
forwardVector = aiVehicle.getForwardVector(baseforwardVector);
subsVector = pointToSeek.subtract(currentPos.clone());
System.out.printf("baseforwardVector: %f, %f, %f\n", baseforwardVector.x, baseforwardVector.y, baseforwardVector.z);
System.out.printf("subsVector: %f, %f, %f\n", subsVector.x, subsVector.y, subsVector.z);
System.out.printf("ForwardVector: %f, %f, %f\n", forwardVector.x, forwardVector.y, forwardVector.z);
if (pointToSeek != null && pointToSeek.x + 3 >= currentPos.x && pointToSeek.x - 3 <= currentPos.x) {
aiVehicle.steer(0.0f);
aiVehicle.accelerate(-40);
} else if (pointToSeek != null && pointToSeek.x > currentPos.x) {
aiVehicle.steer(-0.5f);
aiVehicle.accelerate(-40);
} else if (pointToSeek != null && pointToSeek.x < currentPos.x) {
aiVehicle.steer(0.5f);
aiVehicle.accelerate(-40);
}
} else if (currentState == ObjectState.Stopped) {
aiVehicle.accelerate(0);
aiVehicle.brake(40);
}
}