Friday, 24 February 2017

JavaScript to C# and A*

For this weeks work I decided to port my project from JavaScript over to C#. I made this decision after meeting with Chris for my presentation last week. Originally I decided to program the whole AI in JavaScript as I was more comfortable with JavaScript in inside of Unity as I haven't used C# too much in Unity. As I also had never programmed any AI I decided that using a language which I was more comfortable with was a sensible choice. However one thing that I overlooked when making this choice was that I didn't take into account what languages employers would like you to know. This is because I want this project to be a good piece for my portfolio once leaving University and to help with getting a job. After looking into jobs as both Unity developers and programmers outside of Unity I found that many jobs wanted knowledge of C# with very few mentioning JavaScript. Because of this I felt that it was worth spending the time to port the project to C#.

After porting my project I decided to look into creating my own version of the A* path-finding algorithm as suggested by Chris at my presentation. I started by going back to my research materials to get an understanding of how A* works and the benefits of using this instead of a different algorithm. Ian Millington in the book Artificial Intelligence For Games (Millington, I and J.D.Funge, 2009) mentions that A* (Or a version of A*) is used in many projects due to the efficiency and easy implementation of it. Another resource that I looked at was a YouTube video created by Sebastian Lague (Lague, S. 2014). In this video (and the following videos in the series) look into how A* works and how you would go about implementing this into Unity. After looking at these resources I feel that I would be able to create a version of this so will be spending my next few weeks implementing it into my project.

References
Lague, S (2014) A* Pathfinding. Available at: https://www.youtube.com/watch?v=-L-WgKMFuhE

Millington, I. and Funge, J.D. (2009) Artificial intelligence for games. San Francisco, Calif, Oxford: Morgan Kaufmann; Elsevier Science.

Saturday, 18 February 2017

Attacking, presentation and the future

For this weeks work I planned on starting to implement attacking mechanics and having my presentation at University. I started by adding the ability for the AI to shoot once he gets within a certain range of the player. I had several problems where I couldn't get the AI to stop running towards the player when he was shooting. The current version still doesn't have this working properly. There was also a bug where the sight was raycasting from the AI start position and not updating when he moves. This hasn't been 100% fix but I will be looking back into sorting this at a later date.

My presentation went well with me presenting my progress on my project to Chris (My project supervisor), discussing my project milestones and what I wish I had done differently knowing how my project has gone. After having this discussion with Chris I have decided to port my project from JavaScript over to C#. I've made this decision as C# is a very in-demand language to know for programming jobs. As I want this project to be used in my portfolio and to help me get a job when I leave I feel that it will be worth my time to port my project over now. We also discussed the idea of me programming my own path-finding algorithm as showing I can program my own algorithms is something else that would be useful to show on my portfolio. This is something else I am going to consider doing depending on how much time I have once I have ported over to C#.

For my next weeks work I will be porting the current version over to C#. I am planning for this to take me around 1 or 2 weeks and will be moving any other milestones this effects back until this is done. Once this is completed I will be creating an updated table of my milestones to show what I will be doing next.

Sunday, 12 February 2017

Linking mechanics and creating presentations

For this weeks work I linked together the AI mechanics together (Sight, hearing and pathfinding). This means that he will now path to the player depending on how much he can hear or see (Whereas previously it only went to what it could see). Most of my work this week has been on creating my presentation ready for next week. The presentation is to show my lecturers how my work is going and to get feedback from them on what I'm doing. I will be covering why I decided to create AI for my final project, how each part of the AI works and what I will be doing next. I will also be talking about my project milestones discussing how I've met/not met them and what I have done to deal with meeting/not meeting them.

As well as presenting my presentation to my lecturers I will also be working on creating the attacking mechanics for the AI. This will be having the AI decided when he should attack and also adding the attacking mechanics. How close the AI will get to the player will  be decided on what kind of weapon the AI is using.

Sunday, 5 February 2017

Pathfinding adjustments and Chris meeting

For this weeks work I looked into improving the pathfinding system and also had a quick meeting with Chris to discuss the bug stopping the AI sight raycast from begin at eye level. Firstly I changed the AI way-point system to be more user friendly so instead of having to assign all the way-point markers individually, it now will automatically find the way-points and assign them to an array when found. This makes it much easier to add way-points for the AI characters and saves a lot of time when trying to put loads of AI into the scene at once. A bug was fixed where the game would crash if no way-points were put into the scene as well. If no way-points are selected he will now use his start position as a way-point. One thing I looked into adding was using Gizmos to draw out the path that the AI will take by connecting lines between the calculated path. I decided not to do this as the amount of work that it would have taken wouldn't have been worth it as you could only see this in the scene view. It would also be quite costly as it would be calculating the path between way-points often and having a lot of AI in the scene at once could lead to a significant drop in frames.


AI Pathing


After working on the pathfinding elements I decided to use the animations from the Unity standard assets to set up a basic animation controller. This was so that I could have the character walk, run and idle deepening on what he is doing. I also fixed a bug where running into the character would cause him to spin around while still trying to path towards you. This would cause the AI to break (As he never stopped spinning) and would need you to restart the game to fix it. I also had a meeting with Chris and fixed the raycast so it is now shot from the AIs eye line and not from his feet.

Before bug was patched


For my next weeks work I will be working on creating my presentation which I will be presenting to my lecturers. I will also be linking the sight, hearing and pathing mechanics together so that the AI can react to everything that is happening properly.