Question 2
Question 2
This bonus assignment is optional. If you receive a grade higher than your lowest assignment
mark, this grade will be used to replace your lowest assignment mark.
Compress the folder containing your source files as a .zip for submission.
You do not have to include: node_modules, package.json, and package_lock.json
The primary goal of this assignment is to extend our collision detection algorithm to 1) handle
three ray casts in the central ray + fixed whiskers configuration to search for a collision with an
obstacle and 2) work with multiple obstacles in the scene.
Introduction
Recall from Lecture 7 and 8, we wrote Craig Reynold’s collision avoidance algorithm using one
ray (or vector) from the character to a “future location” that the character will be, a certain
number of frames in the future. The one ray implementation has some limitations, as
occasionally the ray will miss an obstacle, but the character will still hit it (see Figure 1).
Figure 1:
The one ray misses the obstacle,
but the character will still hit it.
There are a number of different configurations that have been used to combat this, one of which
is the “central ray with whiskers” approach. The central ray looks identical to the one ray
approach. The whiskers are short, at a fixed length (not a number of frames in the future, a
vector with a set magnitude), and splayed at a fixed angle on each side of the central ray. In
relation to the character, this will look as follows (Figure 2).
Figure 2:
The central ray with whiskers approach.
Task
In the starter code, you will be presented with a wandering character (using the wander()
steering behaviour) that avoids an obstacle using the one ray approach.
Specifications:
Each ray can only avoid one obstacle at a time. This obstacle should be the closest obstacle to
the character’s location. The obstacles that collide with a ray but are further away will be
ignored.
For each ray, if there is a collision, a steering force will be generated. The final steering force will
be a combination of each force generated to avoid the impending obstacle(s). While each ray
can only avoid one obstacle at a time, each ray can avoid different obstacles.
Hints:
I would suggest starting by extending the original, single ray, avoid collision behaviour to work
with multiple obstacles. To accomplish this, you code should iterate over all of the obstacles in
the scene and check for a collision with each. If there is a collision, check the distance between
the character and the obstacle. Keep track of the closest distance to an obstacle and avoid that
obstacle.