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)
double DistToThisIP = 0.0;
double DistToClosestIP = MaxDouble;
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 (DistToThisIP < DistToClosestIP)
DistToClosestIP = DistToThisIP;
ClosestObstacle = o;
ClosestPoint = Point;
if (ClosestObstacle >= 0)
Vector2D Projection = feelers[flr] - ClosestPoint;
SteeringForce = obstacles.normal * Projection.Length();
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.