For this weeks work I began by looking back at the problem I had in the previous weeks work. This was moving the raycast up so instead of shooting out from the AI's feet it is from his eye level. I was unable to find why the errors were showing up and couldn't find a way to get it to work. I will arrange a meeting with Chris when we are back after Christmas to discuss the problem and how I can fix it.
Next I started to implement the hearing for the AI. I began by looking at the navMesh documentation (Unity, 2017) as I've never used it before but I am using it to calculate the distance the sound was travelling. This is a system that I saw Unity use during their 'Stealth game tutorial' series (Unity, 2013). Once I saw this I felt that this would be the best system to use as it helps with making sure the AI can't hear the player through walls. Learning how to use it now is beneficial as I will also be using it for the AI navigation as well. I managed to get it working so that it would calculate the distance the sound travelled however I was having a strange problem where the distance would constantly increase however neither the AI or player character were moving. I spent several hours worth of work trying to figure out why this was happening as both transforms were not changing and no code was changing any of the variables. I eventually found that in the code the AI's Y value was changing as if he was falling through the world but his transform in the inspector was not changing. I narrowed the problem down to the navMesh agent on the AI and fixed the problem by turning off the auto stop check box.
As I am now going into the Christmas break I am unsure on when I will be able to get work done so will blog whenever I make any progress (Until I got back to University where regular weekly blogs will restart). This will not effect my milestones as I previously planned for this. Ideally I will have the hearing set the players alert status (Similar to the sight does) done by the time I go back to University.
References
Unity (2017) navMesh documentation. Available at: https://docs.unity3d.com/ScriptReference/AI.NavMesh.html.
Unity (2013) Stealth game tutorial. Available at: https://www.youtube.com/watch?v=mBGUY7EUxXQ.
Sunday, 18 December 2016
Saturday, 10 December 2016
More Sight
For this week I continued developing the sight for the AI. I started by looking at what I needed to add for the sight to be completed. The main thing that needed implementing was that the AI should become alert if the player is suspicious for an extended amount of time. It should also stay alert for a short period of time after the player leaves the viewcones. This is to simulate the AI remembering the player so continues to look for him even though he can't be seen.
One problem that I have had while developing this was trying to move the raycast so that it shoots from the AIs eye level instead of from his feet (As it currently does). I have tried adding transform.up and Vector3.up to the enemies position vector but instead of working how it does at feet level I get an error when the player is inside of the viewcone. I have tried several things to see if I could find why this was happening however I am still unsure why this is happening. I will continue to look into this next week and if I can't figure it out I will arrange a meeting with Chris to help me fix this issue.
After this week I have finished implementing the AIs sight however for my project milestones I had assigned myself an additional week to complete this. I will be bringing all of my milestones forward by one week because of this. If I continue to be ahead of my previous milestones after implementing the AIs hearing I will look at adding additional features to implement in the spare weeks that I will have.
One problem that I have had while developing this was trying to move the raycast so that it shoots from the AIs eye level instead of from his feet (As it currently does). I have tried adding transform.up and Vector3.up to the enemies position vector but instead of working how it does at feet level I get an error when the player is inside of the viewcone. I have tried several things to see if I could find why this was happening however I am still unsure why this is happening. I will continue to look into this next week and if I can't figure it out I will arrange a meeting with Chris to help me fix this issue.
After this week I have finished implementing the AIs sight however for my project milestones I had assigned myself an additional week to complete this. I will be bringing all of my milestones forward by one week because of this. If I continue to be ahead of my previous milestones after implementing the AIs hearing I will look at adding additional features to implement in the spare weeks that I will have.
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.
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.
Subscribe to:
Comments (Atom)