Monday, 7 March 2016

Coding - Sight Iteration - John Howard

Task

Create a sight system that allows peripheral vision.
Stage One - Initial Ideas
I spent a while before coding drawing and writing up diagrams like above trying to work out what kind of angles I needed and how I could approach the code. Researching into the unity API and forums I found out that degrees over 360 don't exist in world space. There are just 180 degrees on both side. So I need to cast out the angle comparison in the forward direction To force the AI to only raycast on the front facing side.

Stage Two - Raycasts

I decided to create a distance called raycast system rather than a collider based one. This means the sight doesn't require a bool to activate it just activates at different distances using if statements. Each if statement contains a cone of vision and a debug.ray of a different colour to allow me to test in the scene view when a certain part of the vision cone is being called. By giving larger widths of vision a smaller distance I can start giving the AI some peripheral like vision. I decided to create this script on a static test cube to just be able to see how the sight debugs changes, as seen at the start of this video. Once this was working correctly I put the new sight script onto the cube AI.


Thoughts

I think this script turned out really well. With a little bit of API raycast research I was able to set up an original functional script and get it calling the correct parts of the AI states. The extra cones of vision really help the AI seem more intelligent and reactive.

No comments:

Post a Comment