top of page

MFP: Character Movement and Camera

  • Writer: Daniel James
    Daniel James
  • Jun 14, 2023
  • 2 min read

This project is an isometric action RPG and so the first thing which needed doing was to get our player character visible and moveable from an isometric perspective. This didn't really take much planning or design-work as the blueprint for how this functions is already exemplified in various other games in the genre. I simply had to brush up on my C# raycasting knowledge and I was able to put together the starting point for the game.


Our placeholder player character is simple a capsule with a little visor to indicate his front and a couple of custom metallic materials to make him nicer to look at than the default.

In the components I also added a Rigidbody, Nav Mesh Agent and Player Controller Script which we will go into shortly. I also made sure to lock the X and Z rotation on the Rigidbody to stop our character toppling over.

In the Nav Mesh Agent, I cranked up the angular speed and acceleration to ensure that the movement is instantly responsive.

With the character set up, it was time to get a camera into the scene. I took the default camera, added a Rigidbody to lock all the rotations and added a camera controller script which we will use later to move the camera around. Note that the camera is not set as a child of the player as this would cause unwanted rotations. I experimented with various camera settings such as different FOVs, angles, distances and swapping between perspective and orthographic perspectives but effectually settled on the following settings.

While we are still on the camera, I might as well go into the camera controller. This script keeps at a fixed position relative to the player while following them around and allows you to zoom in and out within comfortable limits.

So we have a player character and a camera that will follow them, so lets get the player moving. In the player controller I start by declaring and assigning my components. The nav agent is declared in the baseCharacter script which the player inherits from. This baseCharacter script is used to store anything shared between the player and enemies but is not super relevant right now, at this stage the nav agent could just have easily have been declared in the playerController.

Then in the update function I raycast to the mouse position on left click and set that spot to be the nav agent destination if it is in the walkable layer which I have created and added the ground to. Don't worry about the targetCharacter and castingAbility stuff in here, that is to do with the ability system.

The movement is as simple as that. Here it is in action:



Comentários


bottom of page