Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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);

    }        
}
share|improve this question
    
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 ;) –  Falle1234 Apr 10 '12 at 14:15
    
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. –  ThorDivDev Apr 10 '12 at 17:14
    
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. –  ThorDivDev Apr 10 '12 at 21:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.