Introduction This post describe a tool I made to help friends artists of mine in their bachelor final 3D game project. It's a tool allowing to easily manage the camera in the game. The game was a third person game during medieval samurai time. They wanted to have a classic third person view, but also contextual views when the character enters specific locations which means they wanted the camera to be fixed in a position (for example a corner of a room) and to face the character position. |
Implementation ideas
CameraManager
- The process calculating the camera location and orientation must be separated in a specific class, a Manager, designed as a Singleton. I named it CameraManager.
- Initially, it's our PlayerPawn class who manage the camera movements, via the CalcCamera(...) pre-defined function. Now this function will only do one thing: to call the camera manager to handle this process by calling its UpdateCamera(...) function.
- The camera manager works with what I called CameraModes. when processing the camera movements, the manager uses the current mode it has been set to, to know how to process it. We can also change the current camera mode to easily modify our camera behaviour and make the camera manager automatically and smoothly interpolate.
- The camera manager keeps track of three modes: the current mode it uses, the previous mode, the default mode. The previous mode can be usefull when you want to go back from the current to the previous mode. The default mode is the mode the manager will use if it has no other mode. Typically, in this game the default mode is of type ThirdPersonCameraMode and is used most of the time.
CameraMode
The four camera modes I made:
- ThirdPersonCameraMode: Giving this mode to our manager will make the camera behave like a third person view, that can be moved using the mouse or the stick. It handles wall collision and can be parameterized with min, max and default distance we want from the character, and also how high we want the camera to look at relatively to the pawn pelvis.
- FixedCameraMode: With this mode, we will have a fixed camera parameterized with a location, default rotation and a boolean to let us choose if the camera must always dynamically look at the pawn.
- FixedThirdPersonCameraMode: very similar to the first one, it's a third person view but where the player can't move the camera aroud the player. It has the same parameters plus one that is the fixed rotation we want th camera to be set to.
- SpyRightCameraMode: It's a very specific mode I made to see what my mode-system allows me to do. This mode should be set when we're hiding behind a wall and when we are close to its right edge. It will allow the player to see slightly behind the wall by moving the camera to the right. It works pretty well but have still a very little bug. Of course, it's very easy to do the same for a left wall edge but I made this mode for a test and it was not necessary for this game so there is no SpyLeftCameraMode.
CameraVolume
Code Overview
CameraManager
BaseCameraMode
ThirdPersonCameraMode
FixedCameraMode
SpyRightCameraMode
CameraVolume (using FixedCameraMode)
The project
I hope this might help or at least give ideas to someone. Don't hesitate to ask if you've got any questions or problems.