Camera design and programming

Hello everyone!

The last few weeks have been a lot about the camera design of our game, and programming it, so this post will explain why the camera is the way it is, and how it was programmed.

Camera design

At first we wanted to have a different camera angle for every event, and also that the camera should be static in its position, and straight up just use a look at function to follow the player. We quickly realized after a playtest that this was not good camera design, and many people became confused with the camera, and how to move around while it was static.

The other weird thing we had done with the camera, was that it followed the players forward, and it you weren’t able to rotate it around the player. This made it awkward to move around, as the player was not really able to rotate completely either.

This meant the whole camera needed to be reworked, and that meant looking at a lot of other cameras for inspiriation. For example, we looked at the camera of the new Zelda game “Breath of the wild” which was very close to what we wanted to have. A simple camera where you use one joystick to steer the player, and one joystick to rotate the camera round the player.

A very good GDC talk I looked at for inspiriation and guidance.

In order to program this, the players forward is the same as the cameras, which meant that the player could just hold the walking joystick forward, and steer with the camera. The player could also walk and at the same time rotate the camera around the player. This is however not optimal as we want the player to feel uncomfortable, and a fast moving camera, where you can look around all the time, does not really comply with our aesthetic goal. However, it does fit our game, considering it’s in the explore/adventure genre as well.

How it is coded

First off I have a float variable which is my wanted rotation angle. Here I add or remove from it by setting it to += the input from the right joystick times the rotation speed. After this I have a variable for the current rotation angle, and then I lerp from the current rotation angle to the wanted rotation angle. This causes a smooth camera follow. The angle is then converted into a rotation to be handled by a quaternion by setting the variable current rotation to be equal to a Quaternion.Euler(0, currentRotAngle, 0). This is to avoid strange things happening with the camera.

Aftet his we also have a camera clipping feature, which will make sure there is a never an object between the camera and the player. The camera sends out a ray from the player position with the direction being the negative forward of the camera. If the ray hits an object, the camera quickly lerps to the position of where the ray hit, and if it no longer hits, the ray quickly lerps back to its defualt position. Source code for the camera script can be found here.

 

 

 

Leave a comment