Tutorial 3


In this week's tutorial, we made a simple script to spawn a enemy where you click on the terrain, and we made the enemy follow the player. 

A raycast detects all colliders from the origin towards a set distance (or infinity), and can return the colliders and the points of collision. We used a simple raycast script to return the position that we clicked on the terrain. Upon a click, a ray is cast from the camera towards the direction of the click, and then returns where it hit the terrain. An enemy prefab is then instantiated at that position.

The enemies use the NavMesh, a map of accessible surfaces (with adjustible parameters). Each enemy is a NavMesh agent, enabling them to use the NavMesh to go towards the player transform. (The moving box is a NavMesh obstable, meaning that NavMesh agents cannot navigate there.)

I made some adjustments to the code so that the enemy will move towards just infront of the player based on the direction and speed of the player as well as the distance between the two.