> For the complete documentation index, see [llms.txt](https://steijn.gitbook.io/devlogs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://steijn.gitbook.io/devlogs/devlog-client/camera-and-movement.md).

# Camera & movement

#### What is the problem I want to solve?

What would be a good way to show multiple points of view to the user while minimizing the amount of motion sickness in the camera sway.&#x20;

#### How will/did I solve this?

We needed two perspective, a sims-like build perspective as well as a first person mode. \
in these we also need to be able to manoeuvre freely and look around. \
the building perspective needs to be able to zoom in and rotate as well.&#x20;

From my previous project i already knew how to set up a cinemachine orbit. \
This time i had to find out how to properly switch between cameras and set the controls properly.&#x20;

To switch between the cameras i used [this link](https://forum.unity.com/threads/programatically-switch-between-virtual-cameras.483165/) Stating that you could use the priority system and adjust those. By doing this the camera used a specific transition so we went over the different transitions and made sure it didn't feel jarring. after some trying and asking the group we settled on "ease in out" this one starts slow, speeds to a medium speed(depending on the time set, we used 1.5s) and slowly lowers its speed by the end. This resulted in the least jarring transition as well as preventing the whiplash feel you'd get when it goes at a high speed.&#x20;

#### What is the result?

{% embed url="<https://imgur.com/I0Wt8sH>" %}
Showcase of my movement + camera system
{% endembed %}

Aside from this i also needed to make the (for now) "character" be able to move using WASD and the arrow keys. \
This was done by setting up the project settings' input manager and making them make some sense as well as then using the following code:&#x20;

```
public void PerformThirdPersonMovement()
{
    transform.LookAt(2 * transform.position - (new Vector3(BuildingCamera.transform.position.x, transform.position.y, BuildingCamera.transform.position.z)));   //face away from camera
    _horizontalInput = Input.GetAxis("Horizontal");          //Get the value of the Horizontal input axis.
    _verticalInput = Input.GetAxis("Vertical");              //Get the value of the Vertical input axis.
    Vector3 move = new Vector3(_horizontalInput, 0, _verticalInput);
    move.x += UIMovementInput.x;
    move.z += UIMovementInput.z;
    move = transform.forward * move.z + transform.right * move.x;
    controller.SimpleMove(move * MovementSpeed);
}
```

This is the third person movement. I need the character to always face away from the camera so the WASD movement is always the forward for the camera. After doing that i get the keyinputs and calculate how the character should move.\
The UIMovementInput is to make it function using the HUD buttons. \
Simplemove is a built-in function of the charactercontroller component which automatically applies gravity and collision preventions so we don't need to do this.

```
public void PerformFirstPersonMovement()
{
    _horizontalInput = Input.GetAxis("Horizontal");          //Get the value of the Horizontal input axis.
    _verticalInput = Input.GetAxis("Vertical");              //Get the value of the Vertical input axis.
    Vector3 move = new Vector3(_horizontalInput, 0, _verticalInput);
    move = FPSCamera.transform.forward * move.z + FPSCamera.transform.right * move.x;   //move forward "towards" the camera face
    move.y = 0;
    controller.SimpleMove(move * MovementSpeed);
}
```

In this POV we don't need the character to rotate a certain way. instead we have to multiply the movement direction by the camera's forward resulting in the character always moving forward for the users point of view.&#x20;

#### What is the quality of the result?

After completing the results i pulled a few contacts that also aren't heavy gamers but office workers. They tested the camera movement, point of view, viewing angles and speed and said they did not have many complaints.  The general consensus was that the movement speed and rotation speed was a bit too high so we've lowered that. They really liked the camera switch animation. \
It also met our definition of done.

To conclude,\
It has proven to suit our needs as well as the client's and can be used the way it is now without too many further adjustments at this time.<br>

#### What is the next step now I have this result?

I will implement the camera into the main scene and plan a control review later down the line to solve resulting issues and get more user tests.
