Simple Click To Move In Unity

Player movement can be accomplished in any number of ways, but one of the most basic is by simply clicking the mouse. While this isn’t quite as simple as WASD in Unity, it’s still pretty easy using the built in navigation features.

First we need to add a Nav Mesh Agent component to our player, which will allow our player to move along a surface.
Next we have to actually bake our nav mesh on our walkable surface. This should work so long as your object is set to Navigation Static.
Once the game objects are ready, it’s only a few lines of code to get click to move working. Just a ray cast from the mouse pointer position to get a destination, then set the navigation to work.

That’s really all there is to it. There are of course more settings you can configure, and if you need a more advanced solution you could use a third party package or even write your own solution, but this is enough for something basic. My recommendation if you need click to move is to give this setup a try, and be sure you actually need a more robust pathfinding solution before you reach for one, as the built-in features may be enough to get the job done.

--

--

Game developer with over 12 years of experience, mainly focused on MMOs.

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
Ben Pielstick

Game developer with over 12 years of experience, mainly focused on MMOs.