 # AI Steering – Devblog #4

These weeks I have implemented the obstacle avoidance behaviour:

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

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
*  =&gt; z = -(Ax + By + D) / C
*  =&gt; x = -(By + Cz + D) / A
*  =&gt; 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 1 Like

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

1 Like