Saturday, 3 December 2016

Sight Beginnings

This week I started implementing the AI characters sight. I began my creating a basic scene with the 3D model from the Unity standard assets and putting in a first person controller so that I could move around the scene so I could test the Unity first person controller.

After I had put together my scene I found a website that I could look at different angles (Visnos, Unknown). I used this so that I could visually see and determine what angle each viewcone will be.

I then started looking at how I could detect the player if he moved within one of the view cones. I looked at using multiple raycasts that would be fired out across the viewcone. One problem I found with this was that I would be using a lot raycasts per viewcone and having 5 viewcones on the player would cause for a lot of raycast per frame (and would increase a lot if multiple enemies were to be put into one scene). Although I didn't go too much into detail of how costly this would be I decided against doing it this way as I want it to be as efficient as possible. I then went with a system that looks at the player position and AI characters position to calculate the angle between them. I then check this angle against the angle of the viewcone to make sure the player could be seen. Finally I shoot a raycast to check that no objects are blocking the AI characters view of the player.

I've made sure to go through and comment all of the code I have written along with making sure that I can easily understand what each part of the code does if I need to come back to it later. I also made sure to use variables for things such as viewcone distances and angles so that it can be easily customised depending on where the enemy would be used.

I plan to further develop the AIs sight over the next week allowing for things such as when you stand at the edge of a viewcone the AI becoming suspicious instead of the AI instantly becoming alert.

All of my work has been uploaded to my GitHub page: https://github.com/ABurton96/GameAI

References
Visnos (Unkown) Angle Visualiser. http://www.visnos.com/demos/basic-angles.

No comments:

Post a Comment