3rd Person Camera

Copyright © 2015-2024 Thomas Enzenebner

Version 1.0.8

Thank you for buying the 3rd Person Camera Asset!

If you have any questions, suggestions, comments or feature requests, please send an email to: t.enzenebner@gmail.com

Visit the forum: https://forum.unity.com/threads/3rd-person-camera-emulating-the-world-of-warcraft-camera-with-smart-pivot-and-thickness-checks.383754/#post-4356535

Beta access: http://enzenebner.com/beta


Upgrade Guide

Update to 1.0.8 from previous versions

Before upgrading, remove the old "3rdPersonCamera" folder before importing as some files were moved.

Update to 1.0.5.8 from previous versions

When upgrading from a previous version add the relevant CameraInputSampling script to the game object. The scripts will throw an error when the CameraInputSampling components are not found and CustomInput is not activated.


How To use 3rd Person Camera

There are several prebuilt camera gameobjects in the "Prefabs" folder to start from. These are:

In this asset there are 7 demo scenes to see how it's done.

Base components

There are 6 basic components which usually can be put safely on the main camera gameobject. (excluding Targetable)


Input System

New Input system Setup

Step 1:

Step 2:

Step 3:

New Input system Usage

For the new input system, only a single component is used CameraInputSampling.

Input bindings can be found in the folder 3rdPersonCamera\Settings\Input\TPC_Input This provides a default scheme to use or edit.

Legacy Input system

In addition when using any of the upper components, a corresponding input sampling component has to be added on the game object with the CharacterController.

There are 3 input sampling components


Basic Setup

Add the following scripts to the main camera gameobject:

The most important option is which Transform to follow. Set this in Target.

Then set the collision layer which layers should be picked up by the camera. (Usually default)

When your target has a collider, which it likely has, it's important to set the Player Layer. The layer of the target has to be a seperate layer (for example "Player" layer) so the 3rd Person Camera can differentiate between player and the surrounding world and resolve self-collisions.

The rest can be tweaked in a number of ways: (Instead of reading this document, the same descriptions can found in each tooltip!)


CameraController component

BASIC SETTINGS

COLLISION LAYER SETTINGS

FEATURES

THICKNESS CHECK SETTINGS

SMART PIVOT SETTINGS

STATIC PIVOT ROTATION SETTINGS

EXTRA SETTINGS

Public variables

Public methods (needed for runtime changes)


FreeForm component:

This script handles the main rotation mechanic of the camera and is used for Freeform camera movement. It's not needed if you just want follow mode! It's dependency is the CameraController. It can be extended with the LockOnTarget component or OverTheShoulder component.

BASIC SETTINGS

STATIONARY SETTINGS

EXTRA SETTINGS


Follow component

This script handles following the target without any manual camera input. Useful for games that handle non-humanoid targets like racing or flying games. Its dependency is the CameraController.

BASIC SETTINGS

SLOPE ALIGNING

BACKWARD MOTION ALIGNING


LockOnTarget component

This script handles locking onto targets. It's dependencies are the CameraController and Freeform component.

BASIC SETTINGS

TARGETABLES SORTING SETTINGS

EXTRA SETTINGS


Targetable component:

Every Target that's focusable needs a Targetable component.


DisableFollow component

Disables follow component at adjustable triggers to allow FreeForm. Its triggers are target motion, time and mouse input.

BASIC SETTINGS


OverTheShoulder component

With this script the camera can change into an aim and release mode by pressing the right mouse button.

BASIC SETTINGS

EXTRA SETTINGS


FreeForm - Camera Input Sampling component (Legacy)

This script handles input sampling and automatically updates the needed input model of FreeForm

INPUT SETTINGS

MOUSE SETTINGS

KEYBOARD INPUT SETTINGS

CONTROLLER INPUT SETTINGS

LOCK MOUSE SETTINGS

EXTRA SETTINGS

Public variables:


LockOn - Camera Input Sampling component (Legacy)

This script handles input sampling and automatically updates the needed input model of LockOnTarget

BASIC SETTINGS

INPUT MOUSE SETTINGS

INPUT KEYBOARD SETTINGS

INPUT CONTROLLER SETTINGS


Shoulder - Camera Input Sampling component (Legacy)

This script handles input sampling and automatically updates the needed input model of OverTheShoulder

INPUT SETTINGS

Public Variables:

Additional setup for controller support: For an easier setup use the preconfigured InputManager.asset from the 3rdPersonCamera/ProjectSettings folder. !Caution! - Doing so will overwrite any InputManager data you already have!

If you get this warning: "Controller Error - Right axis not set in InputManager. Controller is disabled!" you have to set the following axis in the InputManager: "Right_3": 3rd axis "Right_4": 4th axis "Right_5": 5th axis 0 gravity, 0.3 dead, 1 sensitivity are good standard values.

If you need other names you can change them in the script.


Controls for demos


Version History

1.0.8.1

- fixed a clamp bug in LockOnTarget
- renamed "InputManager.asset" to "InputManager.asset.template" to supress the warning
- removed default code generated file "TPC_Input" from base package

1.0.8

- Improved and rewrote every feature
- Added "Adventure" camera for "Follow": 
    Use FollowMode "LookAt" to activate
- Added new Input system bindings:
    Remove the old "CameraInputSampling_xxx" scripts and add the "CameraInputSampling" component.
    Don't forget to change to the new Input System in the Player preferences.
    Control bindings can be found in "3rdPersonCamera\Settings\Input"
- Split demo scenes into its own .unityPackage
- Integrated the free KCC (KinematicCharacterController) for better character movement
  and easier out of the box usage  
- Updated and reformated documentation

1.0.7.2

- The main transform.rotation has been split up in new Quaternions for camera rotation, pivot and smart pivot rotations:
  Not only is the smart pivot now smoothly integrated in the rest of the systems, the new pivot opens up another level of control. Rotations without the camera moving/rotating around.
- Raycast hit sorting has been improved which should solve most jitter issues (Haven't found them while testing)
- Thickness check improvements, more stable results
- Smart pivot ground check improvement where it would not trigger smart pivot on slopes. There is now also an option to have smart pivot only on grounds and/or walls
- Repositioning when colliding has been improved and getting back to the the desired distance should be more stable/smooth
- A new demo scene: car with lock on
- Introduced new parameters:
    Camera Controller
    - Smart Pivot only on ground
    - Pivot Rotation Enabled
    - Smooth pivot: pivot will smoothly slerp to new pivot
    - Custom Pivot: enable to use pivot angles for override
    - Pivot Angles
    Free Form
    - Stationary Mode Horizontal/Vertical
    - Stationary Modes (enum)
        * Free: no limits in angle
        * Fixed: can't move axis
        * Limited: limited in angles
        * Rotate when Limited: limited by angles, when over threshold rotate the camera
    - Stationary max angle Horizontal/Vertical
    Follow
    - Disable time: The default time in seconds the script will be disabled when the player has input in FreeForm
    LockOn
    - Disable time: When there is input in freeform, LockOn will disable the "smooth pivot" mode and enable it after the disable time 

1.0.6.3

- fixed regression in input sampling where camera mode set to Always was not working
- added "Ignore X Rotation" to Follow so the player can look up/down in follow mode

1.0.6.2

- cleanup of prefabs

1.0.6.1

- added MouseCursorHelper for Windows platform to support cursor locking in place
  and not in the center of the screen
- added gamepad button sampling to FreeForm input sampling
- added public bool inputSamplingEnabled to all input sampling scripts
  with which sampling can be disabled (for example when hovering interface elements)
- added forceDirectionFeature to FreeForm input sampling, which handles
  forcing the direction of FreeForm with mouse buttons (for example, only force direction with right mouse button)
- added stabilizeRotation to FreeForm in case the z-rotation starts to drift

1.0.6.0

- added TPC_DEBUG to CameraController which enables debugging options for raycasts visualization.
  Either uncomment TPC_DEBUG in the script directly or define in Unity project settings
- improved unreliable raycast hit handling on edges and sorting for the best results
- improved distance handling on repositions

1.0.5.9

- Fixed a glitch for 0/0/0 offset vectors where the pivot point of the target is inside the collision sphere.
  The offset gets fixed in Awake of the CameraController, during runtime please use UpdateOffsetVector(Vector3) to prevent glitches.

1.0.5.8

- Input sampling of FreeForm, OverTheShoulder and LockOn has been split into seperate scripts
  and a data oriented model is now used for main scripts:
  * FreeForm uses struct CameraInputFreeForm
  * LockOnTarget uses struct CameraInputLockOn
  * OverTheShoulder uses struct CameraInputShoulder

  These scripts are updated with the UpdateInput(CameraInput...) method. This method should be used for 
  custom input sampling scripts

- added CameraInputSampling_X components which samples inputs and automatically updates 
  the according input model with UpdateInput(CameraInput...)
  These scripts can be used as a template for custom input sampling or adding additional inputs
- added component CameraInputSampling_FreeForm
- added component CameraInputSampling_Shoulder
- added component CameraInputSampling_LockOn    

1.0.5.7

- fixed occurances where automatic zooming out failed and the camera would reposition itself too fast
- improved smart pivot transition
- improved camera offset clipping

1.0.5.6

- added headers and tooltips to components and fields to provide easier documentation
- changed smoothTargetValue in CameraController from float to Vector3 to have more control over axis 

1.0.5.5

- added a stabilization for follow/lock on rotations to prevent wrong rotations in Z-axis
- added mouse/keyboard/gamepad input to LockOnTarget for locking on target and switching to next/previous
- improved lock on target mode with weighted distance and angle
- added input properties for aiming and switching sides to OverTheShoulder
- added "forwardFromTarget" to LockOnTarget which provides a more stable sampling of targets when cycling through targets is preferred
  the default mode takes the forward from camera - which gives the best results when cycling isn't needed and the target that is looked at is more important

1.0.5.4

- added forceCharacterDirection to FreeForm so the character turns automatically in the same direction the camera is facing.
  This works only for character controllers that use absolute directions for movement. The demo character controller
  uses relative movement, so it won't work right.
- fixed a sorting bug with occlusion hits
- improved thickness logic for clipping geometry that occurs often in prefab based level design

1.0.5.3

- improved jitter when camera was zooming out against a wall
- improved thickness handling

1.0.5.2

- added min/max distance to CameraController
- added namespace for demoscene scripts

1.0.5

- added an additional camera offset vector for skewed over-the-shoulder camera type of games like "The Division"
  that can either be fixed or controlled via the OverTheShoulder script
- added OverTheShoulder component
- added new scene to demonstrate Camera Offset called "DivisionCamera - DemoScene"
- changed PlayerLayer data type from integer to LayerMask for convenience and the possibility to have more player layers
- added "Smooth Target Mode" and "Smooth Target Value" that lerps to the target position for smoother translations/rotations
  to dampen noisy position changes for either physics or network based games    
- added support for having no target when initializing or starting
- added mouse/keyboard inputs to FreeForm which uses a list of mouse buttons (Integer) and keyboard inputs (KeyCode)

1.0.4

- added smart DisableFollow script to utilize FreeForm + Follow
- added Ball demo scene
- added simple BallController script
- added namespace "ThirdPersonCamera" to scripts
- added more camera prefabs (Basic, Follow, FreeForm and Ultimate (Freeform/Follow/DisableFollow))
- improved smart pivot transition from sloped surfaces
- improved smoothness of alignToSlopes feature
- improved camera when offset clips into geometry
- restored Ethan crouch animation
- removed Ethan air->ground crouch animation

1.0.3

- added 2 new demo scenes (follow and follow+lock on)
- added support for follow mode
- added support for target locking
- split CameraController into CameraController and Freeform    
- improved smart pivot and occurances of snapping
- improved thickness check    
- changed hardcoded raycast layermasks to be configured in the editor

1.0.2

- changed collision sensitivity to be spherical
- removed camera position/rotation initialization, editor values are now taken
- improved smart pivoting and smart pivoting start and resets
- improved detection algorithm when multiple raycasts are hit
- added terrain to demoscene
- added RotateTo public method
- added x/y, playerCollision, Distance public get or/and set

1.0.1

- improved thickness checking
- improved smart pivoting on slopes
- added collision distance to improve clipping occurrences    
- added automatic mouse cursor locking when looking around (currently unstable in WebGL)
- added interface handling to demo scene    
- changed sensitivity handling
- removed unnecessary files
- added a script only package

1.0.0

- initial release