CameraBoom
Keeps a chase camera out of walls: given the point the camera looks at and where it would like to be, update() returns the closest position on that line that no collider blocks. It pulls in at once when something comes between them, and eases back out when it clears.
Obstacles need 3D colliders (BoxCollider3d/SphereCollider3d): a static building is an isStatic entity with a BoxCollider3d. Give them their own memberFlags bit and set collidableFlags to it, so the player's and enemies' own colliders don't pull the camera in.
m.boom = new BGE.CameraBoom(m.game, {collidableFlags: CAMERA_BLOCKER}) camera.position = m.boom.update(lookAt, wantedPosition, dt)
Properties
probeRadius(float) — Thickness of the camera: rays are cast round a circle this wide, and the camera stopsminDistance(float) — Never closer to the look-at point than this, even if blocked closer stillcollidableFlags(integer) — Colliders whose memberFlags overlap this block the cameraeaseOutRate(float) — How quickly the camera eases back out, 1/seconds (higher is faster)closeDistance(float) — isClose() is true within this distance, e.g. to fade out the playergame(BGE.Game)distance(float)blocked(boolean)
Constructor
new CameraBoom(
game: BGE.Game,
args?: roAssociativeArray,
): CameraBoomParameters
game(BGE.Game)args(roAssociativeArray, optional, default: "{}")
Instance Methods
update(
lookAt: BGE.Math.Vector,
desiredPosition: BGE.Math.Vector,
dt: float,
): BGE.Math.Vector
Works out this frame's camera position.
Parameters
lookAt(BGE.Math.Vector) — the point the camera looks at, e.g. the player's headdesiredPosition(BGE.Math.Vector) — where the camera would be with nothing in the waydt(float) — seconds since last frame
Returns
BGE.Math.Vector— the camera position to use
getDistance(): float
Distance from the look-at point to the camera after the last update().
Returns
float
isBlocked(): boolean
Whether something was in the way at the last update().
Returns
boolean
isClose(): boolean
Whether the camera is within closeDistance of the look-at point.
Returns
boolean
reset(): void
Forgets the eased distance, so the next update() snaps straight to the result, e.g. after a cut or a respawn.
Returns
void
unblockedDistance(
lookAt: BGE.Math.Vector,
direction: BGE.Math.Vector,
wanted: float,
): float
Parameters
lookAt(BGE.Math.Vector)direction(BGE.Math.Vector)wanted(float)
Returns
float