Week 8: Prototyping the Camera and Movement in Unity / by Valzorra

In addition to some experimentation and practice with 3D Modelling in Blender, Week 8 was also dedicated to developing a basic prototype in Unity around Project Proposal 4. I should also mention that for now the working title for Project Proposal 4 is As It Lies, so I will be referring to the game with that title in all future documentation until it is changed. The first set of important decisions that needed to be made in regard to the digital prototype was how to the camera and movement within this game would work. To answer both of these questions, I needed to ask myself what is the actual goal of this game, what am I hoping to achieve, and what is the essential experience I want players to go through. For now, I knew I wanted this to be a problem-solving experience where players would have to navigate through an environment by using a series of special abilities. As previously described, the abilities would be determined by the roll of a set of dice and players would be able to control and change the roll to some extent. With that in mind, this game is very much a strategic experience, and I would not like it to be possible for users to punch their way through the level.

Camera Angle

Having narrowed down the overall experience I would like to create, I began analyzing different camera perspectives to try and figure out which one would be the most appropriate one. The first version I analysed was the standard over-the-shoulder or third person camera angle. These type of cameras are usually used when the character and how they act is rather significant to the overall experience, shifting the focus away from the environment. We explored a lovely version of this camera angle in one of our Tech Workshop Session, so I had a pretty good idea of what it would look like in the game. However, I decided against it, because a large part of the screen with a third person camera view is focused on the player’s character rather than on anything else. This would be very problematic because precision and accuracy would be rather important in this strategic problem-solving game. Additionally, the solutions to levels would be incorporated within the level design, which means that the environment would be a major focus of the game. Therefore, I knew straight away that third person was not the way to go for this project.

Example of a Third-Person Camera Angle in Skyrim. Nearly 1/3 of the screen is occupied by the character, which is not ideal for As It Lies, which needs to give you an accurate view of the surroundings.

Example of a Third-Person Camera Angle in Skyrim. Nearly 1/3 of the screen is occupied by the character, which is not ideal for As It Lies, which needs to give you an accurate view of the surroundings.

Since I had established that the layout of the level would be the focus of this game, I started thinking about the potential of a first-person camera angle. First-Person Camera Angles display the game through the eyes of the protagonist, dedicating the entirety of the screen to the environment and the events going on in it. In theory, this sounds perfect for As It Lies, as it will enable players to look at their surroundings carefully, to analyse them, and to figure out how to maneuver their way through. However, even though this is closer to what I would ideally want for the game, it does not focus as much on the strategic and planning elements as much as it could. What is the most crucial about this game is the level layout and the careful positioning of separate abilities. As nice as a first-person camera would be, it does not allow for that careful strategic planning of using your powers. What’s more is that upon further investigation, I discovered that if As It Lies were in first-person, it would echo a series of other games in the genre more than I would like, namely Dishonored. What I want to avoid more than anything else is re-skinning a preexisting game, as that would make the exciting dice-rolling mechanic fade. Therefore, I had to take a look at other options.

As fond as I am of the First-Person Camera Angle, it is not appropriate for As It Lies, because it neglects the strategic elements I want to convey and it makes the game too similar to what’s on the market.

As fond as I am of the First-Person Camera Angle, it is not appropriate for As It Lies, because it neglects the strategic elements I want to convey and it makes the game too similar to what’s on the market.

After taking a look at those two options and realizing they would not work, I began analyzing a Top-Down or Isometric Camera Angle. Top-Down and Isometric Camera Angles places the player above the main action and scenes, often giving them a bird’s eye view of what’s going on. This wide oversight of an area is the most precise and accurate way to make strategic decisions about the environment. This gives the player complete and total control over what is going on in the scene allowing them to make the best possible judgement on how to solve the situation they have been placed in. The only problem with a Top-Down/Isometric Perspective is that is detaches the player from the events, thus making it more difficult to establish an emotional connection. However, the main goal of As It Lies is to provide an exciting experience with environmental puzzles all wrapped up in the context of an exciting world and story. Therefore, as long as players are having fun, emotional attachment to the game is not a priority.

I would like to take this opportunity that the Camera Angle of As It Lies is closest to Top-Down/Isometric, but would likely be a mix between that and the General Third Person View. This combination would still provide enough flexibly for strategy, but would help the player connect with the protagonist and events that are going on more-so than a pure top-down view. Additionally, this would give me more flexibility as I could chose where to lock the camera based on the level and I would not be confined to solid view that’s always straightly vertical to the ground. The closest example I can think of would be the League of Legends Camera System, which is locked into the same position, oftentimes onto the player and follows them as they move. The League of Legends camera system allows for careful strategic decisions and enables players to work together and see everything that’s going on in the scene. For more on Camera Angles, have a look at this fantastic blog post I found on Gamasutra.

A camera angle similar to the one in League of Legends would be ideal for As It Lies.

A camera angle similar to the one in League of Legends would be ideal for As It Lies.

Creating the Prototype and Movement

After I had made my decision about what Camera Angle would work best for As It Lies, the way the player would move in the environment became very straight-forward. Traditionally, Top-Down and Semi-Top-Down Camera Angles are accompanied by a mouse-click system for movement. Therefore, at this stage I knew that I wanted the game to have a Top-Down Camera View, similar to League of Legends in terms of angle, and that the player would move through the environment by using their mouse to click on a target location. Now that I had come to those conclusions, it was time to actually make a prototype in Unity that would showcase how it all works. I would like to note that as I am not a very experienced programmer, I had quite a bit of help from James in the creation of this prototype both during our Tech Workshop Sessions and beyond. Therefore, anything you see from here on out in Unity has been a collaborative effort between the two of us.

To my surprise, crafting a locked Top-Down Camera that would follow the player is actually quite easy to do. The first step of this process was to position the camera adequately, so that it fully shows everything that’s going on in our testing environment. For the purposes of this prototype the Camera was locked in a relatively arbitrary position, above the testing environment and player, in such a way that it would display them efficiently. After that, a basic Camera Move script was created and the first thing that script does is to locate the Game Object in the Scene tagged as “Player“, which in this case is a basic cylinder. After the Player has been located, the script takes into account any changes in the player’s position according to the coordinate system. After those changes have been calculated and assessed, they are applied to the Camera in the same manner, causing the two objects to move simultaneously. That way, the camera is constantly looking at the player from a predetermined angle and is moving along to the actions of the player. Below I have attached a few screenshots of the scene in Unity and the code for the Camera Movement as an image and in text format.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour {
    private GameObject player;
    private Vector3 offset;
    void Start () {
        player = GameObject.Find("Player");
        offset = player.transform.position - transform.position;
    }
    void LateUpdate () {
        MoveCamera();
    }
    void MoveCamera() {
        transform.position = player.transform.position - offset;
        transform.LookAt(player.transform);
    }
}

An example of how the Camera View Point is directly looking at the player. If they were to move, the Camera would directly follow the player, always keeping them in the center of the image.

Programming the Player Movement Script was slightly more challenging as it involved moving the character by mouse click rather than more conventional means such as a controller or keyboard buttons. First of all, I needed to do some work with Unity to determine the areas that could be walked over in this environment. This meant that I would have to bake a Navigation Mesh to indicate that the three green planes on the screen are Walkable Objects. Once that was created, I also needed to indicate which Game Object was the Player. Therefore, I tagged my basic Cylinder as “Player“ and proceeded to attach a Box Collider and a NavMesh Agent to that Cylinder. These Components in combination with the baked NavMesh are what would make the Cylinder move over this very basic environment. Both the Box Collider and the NavMesh Agent have not had any of their default settings altered. Now, with all of those Unity bits and pieces sorted, I could get down to the actual code. The Player Move Script works by saying that if the player presses the Right Mouse Button onto a Walkable part of the environment, then a Ray will be cast from the Camera to the location the Mouse Cursor is directly over. That way, once the player clicks on a part of the environment, then they will be automatically moved toward the location where the mouse was clicked at a predetermined speed. I have attached the code for the Player Move script below.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class PlayerMove : MonoBehaviour {
    private NavMeshAgent nAgent;
    private float currentSpeed;
    void Start() {
        nAgent = GetComponent<NavMeshAgent>();
        currentSpeed = nAgent.speed;
    }
    void Update() {
        GetPlayerInput();
    }
    void GetPlayerInput() {
        if(Input.GetMouseButtonDown(1)) {
            MoveToClick();
        }
    }
    void MoveToClick() {
        nAgent.speed = 0f;
        RaycastHit h;
        if (Physics.Raycast (Camera.main.ScreenPointToRay
                            (Input.mousePosition), out h, 100f)) {
            nAgent.SetDestination(h.point);
            nAgent.speed = currentSpeed;
        }
    }
}

Thoughts and Reflection

These were the first of many scripts to come. James and I designed and crafted the Camera Movement System and the Player Movement System, which will be the building blocks of the entire project. Overall, the process for these two scripts was rather smooth and James and I did not have too much trouble making decisions in regard to them. I did wonder for the longest time whether a first person or a top-down camera perspective would be ideal for this game. However, after seeing the prototype with the top-down point of view, I know we made the right decision, as this perspective accentuates the strategic elements of As It Lies. So far, I think this has been a terrific start to the prototyping process and I look forward to writing more code and designing the algorithms for the abilities, dice rolling and so on.