Mixing Camera
Last updated
Last updated
Sometimes it is very useful to blend multiple cameras and dynamically adapt their weights to runtime properties. For example, when you are fighting against a boss, you can use two lock-on cameras, one for where you're close to the boss and the other for where you are at a far place, with their weights adjusted according the distance between you and the boss. This is particularly useful as you might want to present different views when you are near or far from the target, which is common in most 3A games.
Before going on, make sure you know what MixingCameraExtension is and its tunable parameters.
The easist way to call a mixing camera is to use the CallCamera node in blueprint, as most other cameras do. But before that, you should first create a mixing camera using the MixingCameraExtension and create its sub-camera blueprints. Reference the following instructions to call a mixing camera.
Create a mixing camera. Right click on content browser, select "Blueprint Class", search for "ECameraBase" and click "Select". Add a MixingCameraExtension extension to it. You can also add a resolve occlusion extension. By doing this, you create a new mixing camera. Rename it as whatever you want, for example "MyMixingCamera".
Create sub-cameras. Right click on content browser, select "Blueprint Class", search for "ECameraBase" and clike "Select". This is the sub-camera class you will add to the mixing camera you just created in step 1. Rename it as whatever you like, for example "LockCamera1". You can create multiple sub-cameras using the same step here, but remember to only inherit the "ECameraBase" class.
Set up your sub-cameras. Add optional follow component, aim component and extensions to each of your sub-cameras. For example, here I set each sub-camera as a lock-on camera, i.e., ScreenFollow + TargetingAim but with different parameters.
Go back to your mixing camera, and assign sub-cameras in the mixing camera extension. You can optionally assign follow target and aim target if your sub-camera requires one. You must use approriate Weight Update Scheme and Mix Scheme to make sure the mixing camera behaves in a way you expect. Note that you can also specify the follow component / aim component of this mixing camera. If you do so, it will override the location / rotation returned by sub-cameras if the execution order is approriately set.
The final step is go to where you want to call this mixing camera and use the CallCamera node. If you specified a follow component or an aim component, you may need to provide a follow target or aim target to the corresponding pin.
Now you can see the mixing camera blends between the sub-cameras in viewport.
Notes
For most of the time, you will need the Manual mode for Weight Update Scheme. To this end, you should assign the weights in the Tick event of the mixing camera blueprint, by leveraging the built-in node GetSubCameraOfClass
, GetSubCameraOfIndex
, NormalizeWeights
and SetWeights
. Refer to MixingCameraExtension for complete introductions to these nodes. An example is shown below.
The idea is very simple: use the distance between the follow target the aim target of each sub-camera as the raw weight, and then normalize them via the NormalizeWeights node, the result of which is fed into the final weights. As I expect a larger weight with a closer distance, I use the reciprocal of the raw distance to make up the un-normalized weight array. It looks like a little complicated, but the process is very lucid and is highly customizable.
You should be very careful of mixing camera rotation because it may produce very unpleasant rotation jumps. It's recommended to set the same aim target for each sub-camera, if necessary, or just override the mixing camera's aim component. If you do need to mixing different rotations from different look-at actors, be sure to use the Eigenvalue
mix rotation method.