ThirdPersonCamera
new ThirdPersonCamera(physics : Object, options : Object)Create a ThirdPersonCamera.
Constructor Parameters
physicsObjectPhysics instance
optionsoptionalObjectCamera options
Default is
Default is
{}.canvasoptionalHTMLCanvasElementCanvas element for pointer locktargetoptionalTHREE.Object3DPlayer mesh to followoffsetoptionalTHREE.Vector3Camera offset from targetlockRotationoptionalbooleanLock camera rotation to character movement
Default isfalse.sensitivityoptionalObjectMouse sensitivity
Default is{ x: 0.5, y: 0.5 }.fovoptionalnumberField of view
Default is70.
Properties
# .canvas : HTMLCanvasElement
Canvas element for pointer lock.
# .offset : THREE.Vector3
Camera offset from target.
# .lockRotation : boolean
Whether camera rotation is locked to character movement.
# .sensitivity : Object
Mouse sensitivity for orbit rotation.
# .locked : boolean
Whether pointer lock is currently active.
# .yaw : number
Current yaw angle in radians.
# .yaw :
Set yaw angle in radians.
Methods
on#
on(event : 'lock'|'unlock', callback : function) : thisRegister an event callback.
Parameters
event'lock' | 'unlock'Event name
callbackfunctionCallback function
Returns
this — For chainingoff#
off(event : 'lock'|'unlock', callback : function) : thisRemove an event callback.
Parameters
event'lock' | 'unlock'Event name
callbackfunctionCallback to remove
Returns
this — For chainingupdate#
update(delta : number)Update camera state. Call each frame.
Parameters
deltanumberTime delta in seconds
setOffset#
setOffset(offset : THREE.Vector3) : thisSet camera offset from target.
Parameters
offsetTHREE.Vector3New offset
Returns
this — For chainingsetLockRotation#
setLockRotation(locked : boolean) : thisSet whether rotation is locked to character movement. When enabling lock, automatically snaps camera behind the target and releases pointer lock since mouse rotation is disabled.
Parameters
lockedbooleanLock rotation
Returns
this — For chaininglock#
lock()Manually request pointer lock. Does nothing if lockRotation is enabled.
unlock#
unlock()Exit pointer lock.
dispose#
dispose()Clean up resources and event listeners.