CameraManager

Manages the camera in a game, including handling movements, targeting objects, and avoiding obstacles using a raycaster.

Constructor

new CameraManager(context, object3D, variables)

Parameters:
NameTypeDescription
contextContext

game external context

object3DObject3D

object3D attach to this script

variablesobject

script variables

Classes

CameraManager

Members

cameraDistance :number

Type:
  • number

computeCameraDistance :function

Type:
  • function

currentMovement :Movement|null

Type:

obstacle :THREE.Object3D

When computing camera transform obstacle is considered in the computation

Type:
  • THREE.Object3D

raycaster :THREE.Raycaster

Raycaster to avoid obstacle

Type:
  • THREE.Raycaster

target :Target|null

target object3D

Type:

Methods

computeCameraTransform(object3D, distance, offset, angle) → {Object}

Compute camera transform (position + quaternion) to focus object3D

Parameters:
NameTypeDescription
object3DTHREE.Object3D

object3D to focus

distancenumber

distance from object3D

offsetObject

offset camera position

anglenumber

angle on x

Returns:
  • transform of camera
Type: 
Object

currentMovement()

This function is going to be tick in this.tick.

currentMovement()

This function is going to be tick in this.tick. @see Movement

followObject3D(object3D, distance, offset, angle)

Camera start following object3D target

Parameters:
NameTypeDescription
object3DTHREE.Object3D

object3D to focus

distancenumber

distance from object3D

offsetObject

offset camera position

anglenumber

angle on x

moveToBoundingBox(bb, duration) → {Promise.<boolean>}

Move camera to bounding box

Parameters:
NameTypeDescription
bbTHREE.Box3

bounding box

durationnumber

time movement in ms

Returns:
  • promise resolving when movement is done resolve with true if movement occured false otherwise
Type: 
Promise.<boolean>

moveToObject3D(object3D, duration, distance, offset, angle) → {Promise}

Camera move to object3D

Parameters:
NameTypeDescription
object3DTHREE.Object3D

object3D to focus

durationnumber

time of movement in ms

distancenumber

distance from object3D

offsetObject

offset camera position

anglenumber

angle on x

Returns:
  • promise resolving when movement is done resolve with true if movement occured false otherwise
Type: 
Promise

moveToTransform(position, quaternion, duration) → {Promise.<boolean>}

Move camera to transform (position + quaternion)

Parameters:
NameTypeDescription
positionTHREE.Vector3

target camera position

quaternionTHREE.Quaternion

target camera quaternion

durationnumber

time of movement in ms

Returns:
  • promise resolving when movement is done resolve with true if movement occured false otherwise
Type: 
Promise.<boolean>

setObstacle(value)

Parameters:
NameTypeDescription
valueTHREE.Object3D

obstacle

stopFollowObject3D()

Stop following object3D target

tick()

Step the current movement if there is not follow a target if not nothing