Week 4 - Navigation


Using the terrain I created last week, I created a NavMesh, which provides a traversable environment for objects within the game that are NavMesh agents:


For the portfolio exercise, I first added a moving object to the scene. To do this, I created a simple 3D game object into the scene. I then created a script that moves the object along the x axis between two numbers set within unity. The script simply checks  if the x position of the object is greater that the number set in unity. If it is, it will flip it's direction. This also works in the other direction. The object can be seen in the top right of the following GIF:

Also seen in this GIF is the enemy behaviour that I also created this week. The enemy instantiation occurs on the mouse position. This script uses a raycast, which takes the mouse's screen location when the left click is pressed and instantiates an enemy prefab that I created using the same model as the player. The navigation of the enemies to the player occurs using the Navmesh.SetDestination(player.position) function in unity. This function navigates a path across the NavMesh from its origin to the player denoted by the player.position.

The following GIF shows the enemies following the player around the scene:


Leave a comment

Log in with itch.io to leave a comment.