First Person Camera
Overview
The first person camera in NeoFPS is a companion component for the Unity camera and adds a number of useful features for first person shooters.
Field of View
The NeoFPS camera adds additional functionality for controlling the field of view.
Firstly, it allows a horizontal field of view to be specified instead of the default vertical field of view. This is considered a standard in first person shooters, and a number of players will have their preferred FoV settings that they apply in and FPS games they play.
Secondly, it allows the field of view to be modified and animated using multipliers for zoom effects such as aiming down sights. You can modify and reset the FoV in your scripts using the following methods:
public void FirstPersonCamera.SetFov (float targetFovMult, float aimTime);
public void FirstPersonCamera.ResetFov (float aimTime);
The SetFov method takes an FoV multiplier that multiplies based on the standard field of view settings, along with an aim time that controls the duration of the animation from the existing FoV to the new FoV. The ResetFov method takes the same aim time parameter which controls how long it takes to return to the standard field of view settings.
Camera Offset
The camera offset is a position and rotation offset that can be applied and removed to move and animate the camera within the hierarchy. An example use is the modular firearms' HeadMoveAimer which actually moves the head down to the weapon instead of the weapon up to the camera. This allows a lean angle to be added and for the camera rotation to be modified making for an interesting aim effect. You can modify and reset the offset in scripts using the following methods:
public void FirstPersonCamera.SetOffset (Vector3 posOffset, Quaternion rotOffset, float aimTime);
public void FirstPersonCamera.ResetOffset (float aimTime);
These methods take offset parameters, along with an aim time parameter that controls how long it takes to reach the offset and return.
Events
The first person camera also contains the following event:
public static event FirstPersonCamera.UnityAction<FirstPersonCamera> onCurrentCameraChanged;
Subscribing to this event will notify when the camera changes (when it is being looked through or not). This can be used for things such as enabling a scene or spectator camera if the player dies.
Camera Constraints
To aid in matching the first person camera to an animated character skeleton, whilst still allowing procedural aim-down-sights, NeoFPS includes a simple camera constraints system. The FirstPersonCameraTransformConstraints component will match position and rotation to one or more targets with priority, weight and damping. The component has properties to set up a default constraint (such as the character's skeleton head bone) and then new constraints can be added as required.
For aiming down sights, the CameraConstraintsAimer firearm module sets a camera constraint based on the firearm's root transform with an added offset. This allows the procedural animations to move the gun separate to the aim.
To layer in your own constraints you can use the API:
public void FirstPersonCameraTransformConstraints.AddPositionConstraint(IFirstPersonCameraPositionConstraint constraint, int priority, float blendDuration);
public void FirstPersonCameraTransformConstraints.AddRotationConstraint(IFirstPersonCameraRotationConstraint constraint, int priority, float blendDuration);
public void FirstPersonCameraTransformConstraints.RemovePositionConstraint(IFirstPersonCameraPositionConstraint constraint, float blendDuration);
public void FirstPersonCameraTransformConstraints.RemoveRotationConstraint(IFirstPersonCameraRotationConstraint constraint, float blendDuration);