Camera

Camera extends Object, adding functions and properties to it.
Camera is not creatable, there's only one instance of it. It can only be accessed through its globally exposed variable.

Camera is a shortcut to Client.Camera.

Controls camera movement and position.

Functions

Casts a ray and returns an Impact (can be nil).

The Impact contains information about the kind of thing that's been hit.

local impact = Camera:CastRay()
if impact.Block ~= nil then
  print("block hit:", impact.Block)
end
nil FitToScreen ( Shape target, number screenRatio, boolean spherize )

Fits the target to the screen.

screenRatio indicates the percentage of the screen that should be covered by the target.

When spherize is true, a sphere that contains the target is used to place the camera.

local myShape = Shape(R.usename.myShape)
Map:AddChild(myShape)
Camera:FitToScreen(myShape, 0.6, false)
-- the shape now covers 60% of the screen

When in that mode, the camera rotates around its Target property.

Camera:SetModeSatellite()

Puts Camera in "third person" mode. (looking at local Player, from a behind-the-shoulder perspective)

Camera:SetModeThirdPerson()

Properties

Camera's continuous acceleration.

Default value: {0,0,0}.

⚠️ Acceleration is nil and can't be set if Camera.Physics is false.

-- Acceleration can be used to compensate gravity: 
myObject.Acceleration = -Config.ConstantAcceleration
-- myObject's acceleration is now the invert of 
-- Config.ConstantAcceleration, cancelling it.

Backward is a unit vector (vector with a length of 1). It determines which direction is "backward" for the Camera.

Setting it is a way to rotate the Camera.

Distance (in Map blocks) between Camera and its target.

Down is a unit vector (vector with a length of 1). It determines which direction is "down" for the Camera.

Setting it is a way to rotate the Camera.

Forward is a unit vector (vector with a length of 1). It determines which direction is "forward" for the Camera.

Setting it is a way to rotate the Camera.

Can be set to true for the Camera to be hidden.
Nothing else changes, the Camera remains in the scene and it keeps being affected by the simulation (collisions, etc.).

boolean IsOnGround read-only

true when the Camera is not falling.

⚠️ IsOnGround only makes sense when Camera.Physics is true.

Left is a unit vector (vector with a length of 1). It determines which direction is "left" for the Camera.

Setting it is a way to rotate the Camera.

Position of the Camera in its parent.
In other words, LocalPosition refers to the position of the Camera relative to the {0,0,0} position of its parent.

Rotation of the Camera in its parent.

Nested Object local rotations are combined to obtain the "world rotation" (Object.Rotation), the Object's final on-screen rotation.

number LossyScale read-only

Convenience property that attempts to match the actual world scale as much as it can.

Position of the Camera in the world.

local o = Object()
-- places the object where the local player is
o.Position = Player.Position

Right is a unit vector (vector with a length of 1). It determines which direction is "right" for the Camera.

Setting it is a way to rotate the Camera.

Rotation of the Camera in the world (as seen on screen).

While it usually works for simple operations (like Rotation.X = Rotation.X + someAngle), we advise you to use Number3.Rotate to rotate an object around X, Y & Z axis.

You can also set unit vectors like Camera.Up, Camera.Right or Camera.Forward to orient your object.

local o = Object()
o.Rotation = {0, math.pi, 0}
-- o revolved half a turn on Y axis

-- another way to rotate the object:
o.Forward:Rotate({0, 0, math.pi / 2})
o.Forward = Camera.Forward

What Camera is looking at.

Target accepts several types:
- Number3, for a position in world coordinates.
- Block, for the Camera to look at the center of it.
- Object (including extensions like Shape or MutableShape), for the Camera to look at the center of it.

Up is a unit vector (vector with a length of 1). It determines which direction is "up" for the Camera.

Setting it is a way to rotate the Camera.