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) {
    } 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) {

        } else if (pointToSeek != null && pointToSeek.x > currentPos.x) {
        } else if (pointToSeek != null && pointToSeek.x < currentPos.x) {
    } else if (currentState == ObjectState.Stopped) {

  • \$\begingroup\$ you seem too only be checking to see whether your car has reached its waypoint on the x-axis. If I had to do it I would compare the forward-vector of the car to the difference between the checkpoint and the cars current position. If the 2 vectors were off by more than some thresholdvalue I would have the car steer towards the checkpoint. I hope I make sense ;) \$\endgroup\$ – Falle1234 Apr 10 '12 at 14:15
  • \$\begingroup\$ Yes, you are talking about the forward vector or where the car is facing. Problem is in Jmonkey I am totally lost on how to get this with the vehicleAIControl. \$\endgroup\$ – ThorDivDev Apr 10 '12 at 17:14
  • \$\begingroup\$ with the vehicle it is getForwardVector. I just had problems with the function definition. Still I am starting to see what you mean with the vectors. \$\endgroup\$ – ThorDivDev Apr 10 '12 at 21:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.