Point & Click to Move in Unity

In the current project, I’m doing which has a stealth element, we move by clicking the ground / Point & Click

Let’s start simple… We can simply create our Point & Click with Unity’s Navigation system also called NavMesh.

Baking The Floor

  1. Open your Navigation tab from Window -> AI -> Navigation
  2. Select the Ground Object and in the Navigation Tab click Bake

If you have your Gizmos on you should see that the ground’s color is blue

Making the Player move (with NavMesh and Raycast)

To make the player move we add a simple script to it and we use Raycast to define where we click with the mouse, then we take the position and use SetDestination to move our player to that position.

Before you do these steps, add a NavMesh Agent to your Player

  1. Create script and attach that to player (I created a simple “Player” script)
  2. We need a handle for our NavMeshAgent
  3. And set our Raycast

4. We create a method that we call when we want to move to the position which we just clicked.

  • We set up the ray
  • If we hit something with the ray, we move the information using out, to our hit
  • Then inside the if statement we use SetDestination to make our agent’s new position to the hit.point. Which is the position we just clicked.

And in the update function, we call this method when we click.

And this is how we create a simple Point & Click with Unitys Navigation system. I hope this helped you on your coding/game dev journey! :)

--

--

--

From the beautiful snowy country with a touch of "good" humor? Inspired Unity Developer to learn more.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

pattern_create.rb remake in Python3 (0x1)

How To Deploy WordPress on Kubernetes Cluster (AWS)

Announcing the Official Release of Nabox Chrome Extension

TIL: using string for type annotation in Python

Create AWS EC2 instance using Terraform.

RustFest EU Barcelona 🇪🇸 2019

The Role of Data Virtualization in Digital Transformation

Tryhackme | Nmap

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
Janika Suhonen

Janika Suhonen

From the beautiful snowy country with a touch of "good" humor? Inspired Unity Developer to learn more.

More from Medium

Gamedev Log: “Slash’n’crack” #4 (Unity/C#)

Adding lighting to our URP scene

Use The WASD, Luke!

Using Signal Emitters in Timeline to Access C# Scripts