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
  2. Create a Player.cs script and attach it to the Player gameobject
  3. Pseudocode for Updating player position:

// 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
  • Code

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.




Using cinematography for a 3D stealth game

Recommended from Medium

Team building 101 — Building a team

Don’t flock to GitHub just yet!

Concepts and Sample Frameworks for Software Forecasting

Nabox Weekly Issue 14

When is the right time to do a code audit?

.NET Core & SQL Server Preview on Linux Containers

Be character fall natural case father.

Data Virtualization in the Cloud

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


Technologist and Unity developer

More from Medium

4K Christmas Music by the Fireplace with Wood Crackling Sound

A Bluffer’s Guide to Doctor Who: The Gunfighters

Grim Fandango