Point and Click Movement - Player Pathfinding using a Navmesh
We will be creating a program where the player will move towards a location that we click on the screen.
We will identify this location by creating an object there as a destination marker.
Grab the Unity Level Prefab. This is made using ProBuilder so you might need to add this to your package.
This tutorial uses the new Input System.
Enabling the Input System
First enable the new InputSystem
Go to Window > Package Manager
Switch to Unity Registry and then search for Input System
Click the install button.
If you haven't enabled the input system before for this project Unity will ask to restart.
Save your work and allow it to restart.
There are some additional settings but these are best handled when we first want to handle inputs.
Creating a Level
Create a new scene with a plane on the ground and place some object on it. You might want to use ProBuilder for this.
Position the camera so that you can see the entire scene.
It is often useful to create an empty GameObject to store the elements of the level.
Creating a Player
Now add a player object. This example uses one with a CharacterController.
The player is simply a Capsule with a deformed cube as a visor so we can see the direction it is facing.
Good practice would be to convert the level and player into prefabs.
We now have our level and player. We now need a target to move towards
Creating a destination target
Create a GameObject and place it on the scene.
Change the name of this to Destination or similar. This will be the point that we want our player to move towards.
Make sure that it is easily seen in game view. You could add a material to it.