The Great Fleece: Point & Click Movement, Part 3

Now that the scripting to determine the coordinates when the screen is left-clicked is completed, it’s time to have the Player actually move.

First, a handle to the NavMesh Agent on the Player needs to be created.

Also, make sure to add the UnityEngine.AI namespace at the top like below.

Next, in the Start() method, the _agent is set to the NavMeshAgent on the player using GetComponent.

Now that a handle is assigned, it can be used to set the destination in the Update() method when the mouse is left-clicked. First, I’ll remove the code for creating the cube and replace it with a SetDestination() method, which takes a Vector3 point to move the NavMeshAgent. So the new code will look like this.

Now the player should move to wherever we click in the game.

Well, the player is moving where the mouse is clicked. But it is also clipping through objects on the way to the clicked point. So, in the next article, I’ll go over fixing the clipping issue, which should finish off the basics of the point-and-click movement for the player.

Until next time I wish you all success and good luck in your coding and game development journey.

I'm a Unity developer.

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

Recommended from Medium

A free website, A free domain, A free hosting, A free SSL certificate

Introducing — Mavia Wallet

A junior, a middle and a senior dev walk into a bar and they order an ALTER table

How to simplify enterprise-scale data management (part 4)

DevSecOps applied: Setting up automated security auditing of a node.js app with Bitbucket pipelines

HTTP/1 should die

Interlinked — I’ve finally published my SEO Internal Link Analysis Tool.

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
Brian Branch

Brian Branch

I'm a Unity developer.

More from Medium

Understanding the LookAt Field in Cinemachine Virtual Cameras

Platformer: Player Animation Part 3 (continued)

Unity : Cinemachine and Timeline (Part II)

Light layers in Unity HDRP