Feed me: more

Hi all, a quick post regarding my 1 month project for this round. No major development has been done this week except movement and camera controls. This, due in part for a coding exam for a job. So, for this post, I'll talk about some of the code and parts of Unity I'll be using instead of giving anything fun away.

For those who've never used it, Nav Mesh is Unity's way of dealing with AI path finding. It also makes moving a character in a way similar to Action RPGs like Diablo, Grim Dawn, and Torchlight. On another project I'm writing code for, I've found one issue with this system; all entities have a turning circle the size of a mini-golf course. Are there ways to work around it? Not that I have seen so far. Further experimentation will be required.
Luckily, the code to make a character move isn't too difficult for anyone to get their hands on. All you need is the mouse position, a Raycast, the hit co-ordinate, and the Unity.AI library. Easy!

It should look something like this:

if(Input.GetMouseButton(0))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit))
            {
                _navi.SetDestination(hit.point);
            }
        }

This is called on the Update function.
So _navi is a reference to the NavMeshAgent that's on the player object. So when the left mouse button (LMB for short) is pressed down, a ray is cast from the cursor's position. When it hits anything, it sets the destination for the agent to move. From there, Unity handles the rest by calculating the distance and along with rotating the player object towards the point in a curve.

Next week, I hoep to bring you the game play in a video form (I hope).

Comments

Popular posts from this blog

It's been a while...

Puzzzling Motion - The next 1 month build intoduction

Bits and glitches: Rooms, exploration and command