Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AI and Deep Learning by (50.2k points)

I am studying Artificial Intelligence as a module in my Computer Games Programming course and one of my tasks is coding an effective Obstacle Avoidance steering behavior. I've been using Matt Buckland's Programming Game AI by Example to help me, but the framework I'm using differs quite substantially. Instead of using a detection box I have to use feelers so it's closer to the Wall Avoidance function than Obstacle Avoidance. I have a point in box function, instead of a line intersection function, that takes in a Vector2D (The feelers) and a Rect2D (The obstacles). The code iterates through obstacle size and detects if there is a collision at that point.

After the collision is detected a steering force is calculated to push the agent away from the obstacle

The problem I have is that I don't know if I'm using the right variables in the PointInBox parameters and I'm unable to calculate the steering force because I don't know how to use the Rect2D structure effectively.

I've tried attaching different values to the Rect2D variable "obstacles" but I need to get the closest obstacle and normalize it around the Rect2D (I don't really know how to put into words what my issue is I'm bordering beginner/intermediate when it comes to coding).

Vector2D w019435fSteeringBehaviours::ObstacleAvoidance(Rect2D obstacles)

{

    CreateFeelers();

    double DistToThisIP = 0.0;

    double DistToClosestIP = MaxDouble;

    ObstacleManager* Obstacle;

    int ClosestObstacle = -1;

    Vector2D SteeringForce, Point, ClosestPoint;

    for (unsigned int flr = 0; flr < feelers.size(); ++flr)

    {

        for (unsigned int o = 0; o < Obstacle->GetObstacles().size(); ++o)

        {           

            if(PointInBox(feelers[flr], obstacles))

            {

                if (DistToThisIP < DistToClosestIP)

                {

                    DistToClosestIP = DistToThisIP;

                    ClosestObstacle = o;

                    ClosestPoint = Point;

                }

            }

        }

        if (ClosestObstacle >= 0)

        {

            Vector2D Projection = feelers[flr] - ClosestPoint;

            SteeringForce =  obstacles.normal * Projection.Length();

        }

    }

    return SteeringForce;

}

the closest obstacle is crucial I think and has to be a member of obstacles that is then normalized and multiplied by the projection length. But I'm unable to attach any members to obstacles.

Any help would be greatly appreciated, thanks.

1 Answer

0 votes
by (108k points)

I even don't get how a single Rect2D should be sufficient to describe obstacles. Maybe this is where all your problems start? After a closer look, there are many issues with this code. The pointer to the ObstacleManager is uninitialized. You can refer the following links for a better understanding of the variables:

https://docs.opencv.org/trunk/dc/d84/group__core__basic.html

http://web.cs.ucla.edu/~miryung/Publications/uw08-dissertation-mkim.pdf

Browse Categories

...