Class KCCCamera
The player's camera: follows, orbits, zooms and keeps out of walls, in one of three styles (KCCCameraStyle): third person, over the shoulder, or first person.
public class KCCCamera : MonoBehaviour
- Inheritance
-
ObjectComponentBehaviourMonoBehaviourKCCCamera
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.GetComponent<T>()Component.TryGetComponent<T>(out T)Component.GetComponentInChildren<T>()Component.GetComponentsInChildren<T>()Component.GetComponentInParent<T>()Component.GetComponentsInParent<T>()Component.GetComponents<T>()Component.GetComponentIndex()Component.CompareTag(TagHandle)Component.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.GetEntityId()Object.MemberwiseClone()Object.GetInstanceID()Object.GetHashCode()Object.InstantiateAsync<T>(T)Object.InstantiateAsync<T>(T, Transform)Object.InstantiateAsync<T>(T, Vector3, Quaternion)Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion)Object.Instantiate(Object, Vector3, Quaternion, Transform)Object.Instantiate(Object)Object.Instantiate(Object, Scene)Object.Instantiate<T>(T, InstantiateParameters)Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)Object.Instantiate(Object, Transform)Object.Instantiate<T>(T)Object.Instantiate<T>(T, Vector3, Quaternion)Object.Instantiate<T>(T, Vector3, Quaternion, Transform)Object.Instantiate<T>(T, Transform)Object.Destroy(Object)Object.DestroyImmediate(Object)Object.DontDestroyOnLoad(Object)Object.DestroyObject(Object)Object.FindObjectsOfType<T>()Object.FindObjectsByType<T>(FindObjectsSortMode)Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)Object.FindObjectOfType<T>()Object.FindFirstObjectByType<T>()Object.FindAnyObjectByType<T>()Object.FindFirstObjectByType<T>(FindObjectsInactive)Object.FindAnyObjectByType<T>(FindObjectsInactive)Object.FindObjectsByType<T>()Object.FindObjectsByType<T>(FindObjectsInactive)Object.ToString()Object.nameObject.hideFlags
Remarks
The camera decides only what the player sees. Where shots go is worked out from it each tick in KCCPlayer.PopulateInput (AimConvergence), which is what keeps them on the crosshair when the view is off the character's line.
Fields
DefaultDistance
[Header("Distance")]
public float DefaultDistance
Field Value
DefaultVerticalAngle
Default vertical angle for camera.
[Range(-89, 89)]
public float DefaultVerticalAngle
Field Value
DistanceMovementSharpness
Sharpness for distance movement smoothing.
public float DistanceMovementSharpness
Field Value
DistanceMovementSpeed
Distance the camera moves per notch of scroll wheel.
public float DistanceMovementSpeed
Field Value
Remarks
This is a distance per notch, not a rate: the scroll delta arrives normalised to -1..1
(the Input System's default ScrollDeltaBehavior), so one notch moves the camera
by exactly this much before smoothing.
Half a unit, down from five. Over the usual 0-10 range five gave two notches from fully in to fully out, so the wheel behaved as a toggle rather than a zoom and no intermediate framing was reachable. The value only reads as a "speed" if the delta is a rate; it is not, which is what made 5 look reasonable.
FallbackEyeHeight
[Header("First Person")]
public float FallbackEyeHeight
Field Value
FollowPointFraming
[Header("Framing")]
public Vector2 FollowPointFraming
Field Value
- Vector2
FollowingSharpness
Sharpness for following movement (higher = snappier).
public float FollowingSharpness
Field Value
IgnoredColliders
Colliders to ignore when checking for obstructions.
public List<Collider> IgnoredColliders
Field Value
- List<Collider>
InvertX
[Header("Rotation")]
public bool InvertX
Field Value
InvertY
Invert vertical rotation input.
public bool InvertY
Field Value
MaxDistance
Maximum allowed camera distance.
public float MaxDistance
Field Value
MaxShoulderReach
The farthest the shoulder pivot may sit from the follow point, metres, whatever the player configures.
public const float MaxShoulderReach = 1
Field Value
Remarks
A view bound, not an aim one: the shot no longer depends on where the shoulder is (ShoulderDisplacement). Kept so a hand-edited settings file cannot put the view a body's width away from the character, where the follow point's own obstruction cast would no longer protect it.
MaxVerticalAngle
Maximum vertical angle for camera.
[Range(-89, 89)]
public float MaxVerticalAngle
Field Value
MinDistance
Minimum allowed camera distance.
public float MinDistance
Field Value
MinVerticalAngle
Minimum vertical angle for camera.
[Range(-89, 89)]
public float MinVerticalAngle
Field Value
ObstructionCheckRadius
[Header("Obstruction")]
public float ObstructionCheckRadius
Field Value
ObstructionLayers
Layers to check for camera obstructions.
public LayerMask ObstructionLayers
Field Value
- LayerMask
ObstructionSharpness
Sharpness for obstruction smoothing.
public float ObstructionSharpness
Field Value
RotateWithPhysicsMover
If true, camera rotates with physics mover.
public bool RotateWithPhysicsMover
Field Value
RotationSharpness
Sharpness for rotation smoothing.
public float RotationSharpness
Field Value
RotationSpeed
Speed of camera rotation.
public float RotationSpeed
Field Value
ShoulderDefaultDistance
Distance behind the shoulder when the style is first taken.
public float ShoulderDefaultDistance
Field Value
ShoulderLeft
True to look past the LEFT shoulder: ShoulderOffset's sideways part is mirrored. Changing it slides the view across rather than jumping (ShoulderSwapSharpness).
public bool ShoulderLeft
Field Value
ShoulderMaxDistance
Farthest the wheel takes the view from the shoulder.
public float ShoulderMaxDistance
Field Value
ShoulderMinDistance
Closest the wheel brings the view to the shoulder.
public float ShoulderMinDistance
Field Value
ShoulderOffset
[Header("Over Shoulder")]
public Vector2 ShoulderOffset
Field Value
- Vector2
ShoulderSwapSharpness
How quickly the view slides to the other shoulder (higher = snappier).
public float ShoulderSwapSharpness
Field Value
Properties
ActiveMaxDistance
The farthest the wheel may take the view, in the current style.
public float ActiveMaxDistance { get; }
Property Value
ActiveMinDistance
The closest the wheel may bring the view, in the current style.
public float ActiveMinDistance { get; }
Property Value
EyeMotor
The motor of the character being followed, for its eye height in first person. Optional: without it the eye is FallbackEyeHeight above the feet.
public KinematicCharacterMotor EyeMotor { get; set; }
Property Value
- KinematicCharacterMotor
FollowTransform
The transform the camera follows/orbits around.
public Transform FollowTransform { get; }
Property Value
- Transform
PlanarDirection
The current planar (horizontal) direction of the camera.
public Vector3 PlanarDirection { get; set; }
Property Value
- Vector3
ShoulderDisplacement
How far the view's pivot was moved off the follow point by the shoulder this update: zero in third and first person.
public Vector3 ShoulderDisplacement { get; }
Property Value
- Vector3
Remarks
The crosshair's ray passes through the pivot, so over the shoulder it runs this far beside the character. The owner's aim takes it back out of the launch line (KCCPlayer.ResolveOwnerAim), so a projectile leaves the character exactly as it does in third person, and only the view sits off to the side.
Style
The style in effect. Set through SetStyle(KCCCameraStyle), which keeps each style's own zoom.
public KCCCameraStyle Style { get; }
Property Value
TargetDistance
The target camera distance (zoom).
public float TargetDistance { get; set; }
Property Value
Transform
The camera's transform.
public Transform Transform { get; }
Property Value
- Transform
Methods
ReleaseFollowTarget()
Detaches the camera from the character it was following and puts it back where the scene authored it.
public void ReleaseFollowTarget()
Remarks
Called when the world is left. Writing the transform from outside does not accomplish this: every UpdateWithInput(float, float, Vector3) re-derives both the position and the rotation from this component's own state, so a pose written from a teardown path is undone by the next LateUpdate and the camera ends up framed from wherever the player logged out. Clearing FollowTransform is what makes the restore stick — every update returns early from then on.
Not a one-way door. SetFollowTransform(Transform) is how the next character adopts the camera, and it re-seeds the direction from that character, so the state reset here is not something a later session inherits.
SetFollowTransform(Transform)
Sets the transform that the camera will orbit/follow.
public void SetFollowTransform(Transform t)
Parameters
tTransformThe target transform to follow.
SetStyle(KCCCameraStyle)
Changes where the view is taken from, keeping the zoom each style was left at.
public void SetStyle(KCCCameraStyle style)
Parameters
styleKCCCameraStyleThe style to use. An undefined value is taken as ThirdPerson.
Remarks
Safe before a character has claimed the camera: the style is held and used from the first update. The view's heading and pitch are untouched, so switching never turns the player.
UpdateWithInput(float, float, Vector3)
Updates camera position and rotation based on input and deltaTime. Handles rotation, zoom, following, obstruction, and framing.
public void UpdateWithInput(float deltaTime, float zoomInput, Vector3 rotationInput)