Monday, February 25, 2019

Week 23 + 24

Week 23 + 24:

Creating An Enemy NPC - Part 4:

This week, I will now be making the “Monster” wander around the Map from a random position and have it just kind of patrol around the area. Additionally, I also wanted the “Monster” to become “Idle” and even “Attack” the Player. In order to do this, I began by re-opening the “Monster Script” began modifying the following pieces.


So, with this piece of coding the “Monster” is instructed to walk randomly around the “Map”. Working with the other coding, the “Monster” will walk towards the Player if they have spotted them and go “Idle” if they loose track of the Player.


So, now, with these pieces of coding added the “Monster” will now actively wander around the Map and an attempt to search for the “Player”. Upon locating the “Player”, the “Monster” will then give chase and follow the “Player”, and when they finally catch up to the “Player” the “Monster” will then kill them.  If they lose track of the “Player”, however, the “Monster” will return to its “Idle” state and attempt to re-search for the “Player”.

However, though, in order for me to be able to use this script completely I needed to create another script that allowed the “Monster” to see the “Player” character. In order to do this, I needed to create a cone but Unity does not use cones, so I needed to create a script that generates said cone. To do this, I went to the “Scripts” folder and created a new C# Script that I named “CreateCone”. I found a script for the cone from the Unity Wiki: http://wiki.unity3d.com/index.php?title=CreateCone


I then went into “CreateCone” and pasted the script into it. I then saved it and then dragged it into the “Editor” folder, and let it compile. In "GameObject, I then went into "Create Other" and was then able to generate the cone. In the box, I then edited the following "Num Vertices" = "10", "Radius Top" = "0.5", "Radius Bottom" = "3", "Length" = "8", "Opening Angle" = "0", added the "Outside" option and the "Add Collider" option.

 

I then clicked the “Create” button. Once I had created the “Cone”, I then renamed it “Eyes” before I dragged it and attached it to the “Monster”. I then pressed the “Reset” widget, so the cone shape would then appear on screen in front of the “Monster” itself and now the “Monster” itself should be able to see the “Player” when they appear in front of them. After this, I also clicked on the “Convex” and “In Trigger” options.


Finally for this week, I added some more code to the "Monster" script in order to work the "Cone" script I had found and added previously. Basically, this script works in tandem with the other script and makes everything in the above above scripts to work as intended. 

No comments:

Post a Comment

Week 34

Week 34: Critical Reflection: Conclusion: Over the course of this college year, I have managed to design, create and test my Horror-ba...