My journey becoming a Unity game developer: Player Movement-Point and Click game setup

Rhett Haynes
4 min readOct 20, 2021

Objective: Bake the room’s floor to setup AI navigation for the security guards. Plus, create a Point & Click system for the player to use.

Point and Click setup for the player movement.

We want to now create a way for the security guards to move around the auction room when they’re on patrol. This will be done by using the Navigation system provided by Unity. Click on Window->AI->Navigation and click on the Bake tab. We’re going to use the collider on the floor’s surface which is the FloorCollider game object to bake the NavMeshes on for the security guards to navigate. After clicking on the FloorCollider game object, inside of the Bake tab click on the Bake button to bake the floor. When finished it will turn the areas where AI controlled characters can walk into a Light Blue color.

Baking the floor using the Floor Collider game object.

Next, let’s position the Main Camera to the area where it will show Darren progressing through the patrolling Security Guards. We have game objects that are positioned to show where Darren is at in the room as he progresses through the obstacles under Camera Progression Angles game object. Move the Main Camera inside of the Camera Progression Angles game object, and click on Camera One object. Copy the Transform component values by clicking on the hamburger menu as these values will be used to place the Main Camera to this position. Go back to the Main Camera object, and Paste the Transform’s component values to it which will position the Main Camera officially to the location of Camera One. Then move the Main Camera outside of the Camera Progression Angles game object.

Main Camera positioned to Camera One from Camera Progression Angles game object.

After positioning the Main Camera, we will create a Player prototype to help with creating the player’s movement. Create the Player by using the Capsule 3D object, and position it where Darren will be hiding behind the glass case when he slides down the rope. Also, create a C# script, name it Player, and place the C# script inside of the Player game object.

Capsule created to represent the player prototype.

In the Player script, we want to create a Point-Click system where the location the mouse pointer is clicked will be where Darren moves to. Inside of the Update() function, we’re going to check if the mouse button has been pressed. If the mouse button is pressed, let’s create 2 variables first that will create the ray that will shoot out from the Main Camera and check to see what collider’s object the ray hit.

The first variable type will be a Ray with the name of rayOrigin that will use the Main Camera to shoot a ray through a screen point from the mouse position clicked. The second variable type will be a RaycastHit with the name of hitInfo which will give the collider’s object that was hit information.

Now we’re going to check if the Raycast is being used through the Physics engine. If so, we want to check the origin of the ray and the collider’s object the ray has hit. We can use the Debug.Log to print out the objects hit information in the console.

We’re going to create another variable which will be a GameObject name cube that will create a Primitive Type cube game object. Then with this cube variable set its Transform position to equal where the ray hits the collider at that point in world space.

When we click around the room area, we will see new cubes appear onscreen at the point where the mouse button was clicked in world space.

New cubes created where the mouse pointer is clicked at.

Next time we will work on the player’s movement itself.

--

--