Baking the floor, point and click movement.

Point and click, a simple concept in a game. You point the mouse and your character moves to where you hit. There are a few things that I needed to do.

This is the floor collider, with this we can work with the Navigation system in Unity to so called BAKE the Navigation in relation to this.

As simple as that, we now have this blue baked floor. Now to the scripting!

To make this work, I had to work with something called RayCasting. Think of it like shooting lasers at something to return a point. In this case I have set the RayCast to start from my mouse's position. We get the hit location information via RaycastHit and put it into a Variable called hitInfo.

Now all we need to do is set the destination for the NavMesh on the Player (This is _agent).

It moves! But something is not right. It is clipping through everything!

A final thing that needs to be done is to rebake the floors after selecting all the objects in the scene and turning them static in the inspector.

After the rebake, you notice that we actually have areas that are not blue, Unity automatically did to so denote areas that cannot be moved to by the NavMesh, amazing!

Automation is quite marvelous isn’t it? With this I have proper player movement within the game. Definitely will come in handy for some future projects I had in mind!

See you next post!