Player Movement: Point & Click to Move in Unity

Goal: Creat the Point & Click function to control the movement of the player

  1. Create a Scripts folder in the Project tab to store all the upcoming scripts

// if left click
//cast a ray from mouse position (Raycasting: origin, and the hit position)
//debug the floor position hit

4. Move the player along the NavMesh

  • Pseudocode
    // Create a handle to nav mesh agent
    // In Start(), assign the handle to the NavMesh component
    // In Update(), handle.position = hitInfo.point

1. Add a new name space to allow access to the NavMesh component

2. Create handle and assign NavMeshAgent

3. Set handle positionto hitInfo

Now, the player will move to the clicked position, but right now, it will go through the counters.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store