AI Steering – Devblog #4

These weeks I have implemented the obstacle avoidance behaviour:

[video]3D Steer Behaviors with Java: Obstacle Avoidance - YouTube

For further details visit: http://jmesteer.bdevel.org/devblog/#d4

As always you can download the demos here: http://jmesteer.bdevel.org/devblog/downloads/SteerDemos_1-8.zip

The next week I will extend the obstacle avoidance to neighbour avoidance.

4 Likes

I forgot to mention that I developed a function to calculate a random vector inside a plane, Maybe can I add it to the jme plane class ?

Here is the code:

[java]
//Generates a random vector inside a plane defined by a normal vector and a point
private Vector3f randomVectInPlane(Vector3f planeNormalV, Vector3f planePoint)
{
Random rand = FastMath.rand;

    /* Plane ecuation: Ax + By + Cz + D = 0 
     *  => z = -(Ax + By + D) / C
     *  => x = -(By + Cz + D) / A
     *  => y = -(Ax + Cz + D) / B
     */
    float a = planeNormalV.x;
    float b = planeNormalV.y;
    float c  = planeNormalV.z;
    float d = -(
                    (a * planePoint.x) + 
                    (b * planePoint.y) + 
                    (c * planePoint.z)
                );
    
    float x, y, z;
    
    if(c != 0)
    {
        x = rand.nextFloat();
        y = rand.nextFloat();
        z = -((a * x) + (b * y) + d) / c;
    }
    else if(a != 0)
    {
        y = rand.nextFloat();
        z = rand.nextFloat();
        x = -((b * y) + (c * z) + d) / a;
    }
    else if(b != 0)
    {
        x = rand.nextFloat();
        z = rand.nextFloat();
        y = -((a * x) + (c * z) + d) / b;
    }
    else
    {
        x = rand.nextFloat();
        y = rand.nextFloat();
        z = rand.nextFloat();
    }
    
    Vector3f randPoint = new Vector3f(x, y, z);
    
    return randPoint.subtract(planePoint);

}
[/java]

Cool stuffs :slight_smile:

1 Like

Hm that method is indeed quite usefull fo a bunch of other applications.

1 Like