Copyright © 2015-2024 Thomas Enzenebner
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
Before upgrading, remove the old "3rdPersonCamera" folder before importing as some files were moved.
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.
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.
There are 6 basic components which usually can be put safely on the main camera gameobject. (excluding Targetable)
CameraController
The main script and always needed for the following scriptsFreeform
Orbital script to look around 360 degrees with a given distance and user inputFollow
Enables automatic camera movement without user inputOverTheShoulder
Using this in default mode, the camera is able to move left or right with a given input without changing the direction
to the target.DisableFollow
Helper script to disable follow on certain conditions LockOnTarget
Enables locking on gameobjects with a Targetable component. LockOn will keep the target in the middle
of the screen without user input.Targetable
This component makes the gameobject available for the LockOnTarget componentStep 1:
Step 2:
Step 3:
TPC_Input.cs
in 3rdPersonCamera\Settings\Input\
TPC_Input
input schema, trigger a change and
resave.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.
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
CameraInputSampling_FreeForm
Needed when FreeForm is usedCameraInputSampling_LockOn
Needed when LockOnTarget is usedCameraInputSampling_Shoulder
Needed when OverTheShoulder is usedAdd the following scripts to the main camera gameobject:
CameraController
FreeForm
CameraInputSampling_FreeForm
(Legacy Input) or CameraInputSampling
(New Input System)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!)
Target
(Transform)Desired Distance
(float)Collision Distance
(float)Offset vector
(Vector3)Camera Offset
vector (Vector3)
DisableZooming
(bool)
Zoom Out Step Value
(float)Occluded Zoom In Speed
(float)Unoccluded Zoom Out Speed
(float)Camera Offset Change Speed
(float)Camera Offset Min Distance
(float)Hide Skinned Mesh Renderes
(bool)Collision Layer
(LayerMask)Player Layer
(LayerMask)Occlusion Check
(bool) Smart Pivot
(bool) Thickness Check
(bool) Smooth Target Mode
(bool)Smoothing Target Value/Speed
(Vector3)Max Thickness
(float) Smart Pivot only on ground
(bool)Floor Normal Up
(Vector3)Max Floor Dot
(float)Pivot Rotation Enabled
(bool)Smooth pivot
(bool)Custom Pivot
(bool) Pivot Angles
(Vector3)Max Raycast Hit Count
(int)Max Thickness Raycast Hit Count
(int)playerCollision
(get/set)Distance
(get)UpdateOffsetVector(Vector3)
UpdateCameraOffsetVector(Vector3)
InitFromTarget()
or InitFromTarget(Transform)
CameraControllerState GetControllerState()
GetCameraPosition(in CameraControllerState, Vector3 targetPosition)
Get the unoccluded/desired camera positionThis 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.
Camera Enabled
(bool) Rotation Speed
(Vector2)Min/Max distance
(float) Min/Max Angle limit
(float) :StationaryModeType
:Stationary Mode Horizontal
(StationaryModeType)Stationary Mode Vertical
(StationaryModeType)Stationary Max Angle Horizontal
(float)Stationary Max Angle Vertical
(float)Smoothing
(bool)Smooth speed
(float) Force character direction
(bool)Stabilize rotation
(bool)Custom Input
(bool)Looking backwards enabled
(bool)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.
EnableFollow
(bool) FollowMode
(enum)Rotation Speed
(float) Tilt Vector
(Vector3) Disable Time
(float)EnablePreemptiveSweeping
(bool)SweepSpeed
(float)Align on Slopes
(bool) Rotation speed slopes
(float)Align direction downwards
(bool) Ground Layer Mask
(LayerMask) Look Backwards
(bool)Check Motion for Backwards
(bool) Backwards Motion Threshold
(float) TAngle Threshold
(float) This script handles locking onto targets. It's dependencies are the CameraController and Freeform component.
Follow Target
(Targetable) CastRadius
(float)Rotation Speed
(float) Tilt Vector
(Vector3) Normalize Height
(bool)Disable Time
(float)Default Distance
(float) Angle Weight
(float) Distance Weight
(float) Forward from target
(bool) Custom Input
(bool)Max allocated targets
Every Target that's focusable needs a Targetable component.
Offset
(Vector3)Disables follow component at adjustable triggers to allow FreeForm. Its triggers are target motion, time and mouse input.
activateMotionCheck
(bool) activateTimeCheck
(bool) activateMouseCheck
(bool) timeToActivate
(float) motionThreshold
(float) With this script the camera can change into an aim and release mode by pressing the right mouse button.
Aim offset length
(float) Aim distance
(float)Release distance
(float)
Base Offset
(Vector3)
Slide Axis
(Vector3) Additional Axis Movement
(Vector3) Custom Input
(bool)This script handles input sampling and automatically updates the needed input model of FreeForm
Camera Mode
(enum)Mouse Input
(ListMouse Sensitivity
(Vector2)Mouse Invert Y
(bool)Keyboard Input
(ListController Enabled
(bool)Gamepad/Button Input
(ListController Invert Y
(bool)Controller Sensitivity
(Vector2)Lock Mouse Cursor
(bool)Keyboard Input Toggle
(KeyCode)Keyboard Input Cancel
(KeyCode)Force Direction Feature
(bool)Mouse Input Force Direction
Public variables:
InputSamplingEnabled
(bool)This script handles input sampling and automatically updates the needed input model of LockOnTarget
Cycle cooldown
(float)Mouse LockOn Input
(ListMouse - Cycle target Next
(ListMouse - Cycle target Previous
(ListKeyboard LockOn Input
(ListKeyboard - Cycle target Next
(ListKeyboard - Cycle target Previous
(ListGamepad/Button LockOn Input
(ListGamepad/Button - Cycle target Next
(ListGamepad/Button - Cycle target Previous
(List
Public Variables:
InputSamplingEnabled
(bool)
Hidden in inspector, enables input samplingThis script handles input sampling and automatically updates the needed input model of OverTheShoulder
Input Mouse Aim Mode
(ListInput Keyboard Aim Mode
(ListInput Gamepad Aim Mode
(ListInput Mouse Change Leaning
(ListInput Keyboard Change Leaning
(List<KeyCode) Input Gamepad Change Leaning
(ListInputSamplingEnabled
(bool) 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.
- 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
- 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
- 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
- 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
- cleanup of prefabs
- 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
- 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
- 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.
- 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
- fixed occurances where automatic zooming out failed and the camera would reposition itself too fast
- improved smart pivot transition
- improved camera offset clipping
- 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
- 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
- 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
- improved jitter when camera was zooming out against a wall
- improved thickness handling
- added min/max distance to CameraController
- added namespace for demoscene scripts
- 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)
- 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
- 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
- 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
- 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
- initial release