CameraRig class final
The part of a chasing camera that every chasing camera has.
Not a camera. It has no idea where it wants to be — a caller works that out, from a heading and a pitch in one game and from a car's speed and the track ahead in another — and hands it over. What lives here is everything after that: easing towards it without overshooting, carrying knocks and shakes that fade, and staying out of the walls.
Composed rather than inherited from. A base class would have had to carry the platformer's yaw and pitch, which a car does not have, or the racing camera's track distance, which a runner does not — and a base class that knows about both is the engine learning what a lap is.
The ordering is the point
place does five things in an order that took a property test to get right, which is why it is one method and not five. In particular the wall check runs on both sides of the impulses, and both are needed: before, so that a knock is added to a camera already where it belongs rather than to one halfway inside a wall; after, because a knock is a displacement like any other and a camera inside a brush is the one thing this exists to prevent. Three hundred random impulses in a boxed room found it half a metre into the wall behind the player.
Constructors
- CameraRig({required CollisionWorld world, double impulseDecay = 9.0, double nearClearance = 0.35, double minDistance = 1.2, int wallMask = CollisionLayers.world})
-
A rig kept out of
world's walls onwallMask. Defaults: impulses fade at 9 per second, 0.35 metres of wall clearance, pulled in no closer than 1.2 metres.
Properties
- extraFieldOfView → double
-
Extra field of view, in radians, that decays away. Read by whoever owns
the projection.
no setter
- eye → Vector3
-
Where the camera is. Valid after the first place.
Where the camera is this frame, walls and impulses and all.
no setter
- freeEye → Vector3
-
Where the camera would be with nothing in the way and nothing shaking it.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- impulseDecay → double
-
How fast a kick, a widening and a shake fade: the fraction gone each
second, per second.
final
- isPlaced → bool
-
Whether the camera has been put anywhere yet.
no setter
- minDistance → double
-
How close to what it is watching the camera may be pulled before giving
up, in metres.
final
- motion ↔ double
-
How much of the camera's involuntary movement the player asked for,
from nought to one.
getter/setter pair
- nearClearance → double
-
How far in front of a wall the camera stops, in metres.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- target → Vector3
-
What it is looking at, as a copy.
no setter
- wallMask → int
-
Which layers count as something to be kept out of.
final
- world → CollisionWorld
-
Where the walls are, for keeping the camera out of them.
final
Methods
-
cut(
) → void - Forgets where the camera was, so the next place is a cut.
-
keepOutOfWalls(
) → void - Pulls the camera in until the line from what it watches to it is clear.
-
kick(
Vector3 direction) → void -
Knocks the camera along
directionby its length, in metres. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
place(
{required Vector3 desiredEye, required Vector3 desiredTarget, required double lag, required double dt}) → void - Puts the camera where it should be for this frame.
-
shake(
double amount, {double seconds = 0.35}) → void -
Shakes the camera for
seconds,amountmetres wide. -
toString(
) → String -
A string representation of this object.
inherited
-
widen(
double radians) → void -
Widens the view by
radians, which decays back. For speed, a dash, a boost.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited