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
I wanted to make something easy to use, both for me as a programer but also for the artists. The next points describe my implementation ideas.
- 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
Don't be afraid if you didn't understand clearly yet what a camera mode is and how it works. Describing the four camera mode I made will help you to get it.
The four camera modes I made:
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
Camera Volume is a derived class of Volume and can be instanciated inside the Unreal Editor. It has a FixedCameraMode property attach to it. You can set all of the mode parameters directly through the editor, on the camera volume property panel. This Volume act very simply: when the pawn enter it, the camera change accordingly to the fixed camera mode set in the volume. When the pawn leave the volume, the manager goes back to its previous mode.
Code Overview
I won't put all the game sources here because the project doesn't belong to me but I'll put everything I described earlier and it's enough to be fairly simply re-used in another project. The classes don't necessarily have the exact same name as implementation name I gave before, and started by "Mugetsu" that is the game name.
CameraManager
The camera manager must be used as a Singleton and must be a member created and handled in the PlayerPawn script.
BaseCameraMode
It's the class which all camera mode should derived from.
ThirdPersonCameraMode
FixedCameraMode
SpyRightCameraMode
CameraVolume (using FixedCameraMode)
The project
Just a small part for interested people that wanted to know more about this project. You can find additional info just here, and I will probably write a few lines about it later on my Project blog page, on this portfolio.
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.
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.