The solution I decided to go with was taking the contact normal of the center ray's collision with the obstacle and rotate in the general direction where the contact normal was pointing. While the original goal of the project was to use a single raycast, I was unsatisfied with the results that a single raycast was bringing and decided to add two more raycasts, one on each side of the agent creating a cone of vision for the agents.
If the ray on the object's left hits something, then the agent steers to the right to avoid it, and vice versa. However, when both the left and right rays hit something it will choose to avoid the obstacle closer to the agent, as the closer object is a more imminent threat to its goal of avoiding obstacles.
I recorded two videos to showcase the difference between using one raycast and three raycasts:
Komentarze