Camera

The Camera object can be aquired by calling this.scene().camera(). With it you can manipulate the attributes of your game’s camera.

Function Description
farPlane()

Returns the far render distance of the camera.

fieldOfView()

The field of view is the extent of the observable world that is seen at any given moment.

nearPlane()

Returns the near render distance of the camera. This is the minimum distance from the camera that an object will be rendered.

orthoScale()

Returns the orthographic scale of the camera (only works if camera projection is orthographic)

position()

Returns the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will return {0, 0, 0} until the relative position is changed with setPosition(), even if you adjust the camera position in the settings.

projection()

Returns the projection type of the camera. There are only two possibilities, kPerspective or kOrthogonal.

rotation()

Returns the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will return {0, 0, 0} until the relative rotation is changed with setRotation(), even if you adjust the rotation of your camera in the settings.

screenToWorld(screenPoint)

Converts the given Vec2 screenPoint to a 3D World Position.

setFarPlane(value)

Sets the far render distance of the camera. This is the maximum distance from the camera that an object will be rendered.

setFieldOfView(value)

This function sets field of view of the camera. The field of view is the extent of the observable world that is seen at any given moment.

setFollowThreshold(x, y, z)

Sets the follow threshold of the camera. This determines how far the followed object can get from the camera before it starts moving. Also accepts a Vec3 optionally instead of x, y, z.

setNearPlane(value)

Sets the Near Render Distance of the camera. This is the minimum distance from the camera that an object will be rendered.

setOrthoScale(value)

Sets the orthographic scale of the camera (only works if camera projection is orthographic)

setPosition(x, y, z)

Sets the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will not override a camera’s position in the settings, but adjust the position relative to the original camera position.

setPositionFollow(value)

Sets which object the Camera will follow. There are three options you can pass. “None” – Camera will not follow anything
“Game Path” – Game Path will be followed
“Character” – Any Entity that is considered a Character will be followed

setProjectionMatrix(matrix)

Sets a custom projection matrix. https://en.wikipedia.org/wiki/Projection_matrix

setRotation(x, y, z)

Sets the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will not override a camera’s rotation in the settings, but adjust the rotation relative to the original camera rotation.

setRotationQuat(value)

Sets the “additional” rotation as quaternion. Note that unlike in Entity, these “setRotation” and “setRotationQuat” are independent, meaning that the result rotation will be a sum of these two.

setWorldPosition(x, y, z)

Sets the actual position of the camera, the same way it is set in the camera settings panel. If the camera is set to follow position of a character or path, it will act as an offset. Take care when using setWorldPosition and setPosition together, as setPosition sets a relative position based on the camera’s world position.

worldPosition()

Returns the actual position of the camera. This is the same position as the one set in the camera settings panel.

worldToScreen(x, y, z)

Projects a World (3D) position into Screen (2D) coordinates.


farPlane()

Returns the far render distance of the camera.

Returns

number The Far Render Distance of the camera. This is the maximum distance from the camera that an object will be rendered.

↑ Back to top


fieldOfView()

The field of view is the extent of the observable world that is seen at any given moment.

Returns

number the field of view of the camera.

↑ Back to top


nearPlane()

Returns the near render distance of the camera. This is the minimum distance from the camera that an object will be rendered.

Returns

number The near render distance of the camera.

↑ Back to top


orthoScale()

Returns the orthographic scale of the camera (only works if camera projection is orthographic)

Returns

number the orthographic scale of the camera

↑ Back to top


position()

Returns the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will return {0, 0, 0} until the relative position is changed with setPosition(), even if you adjust the camera position in the settings.

Returns

Vec3 the {x, y, z} relative position of the camera.

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.position()); // result: {0, 0, 0}
camera.setPosition(0, 10, 0); // the camera still follows the Character, but 10 units higher
log(camera.position()); // result: {0, 10, 0}

↑ Back to top


projection()

Returns the projection type of the camera. There are only two possibilities, kPerspective or kOrthogonal.

Returns

string “kPerspective” if the projection is Perspective, “kOrthogonal” if the projection is Orthogonal

↑ Back to top


rotation()

Returns the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will return {0, 0, 0} until the relative rotation is changed with setRotation(), even if you adjust the rotation of your camera in the settings.

Returns

Vec3 the {x, y, z} relative rotation of the camera.

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.rotation()); // result: {0, 0, 0}, regardless of camera settings
camera.setRotation(30, 0, 0); // the camera still follows the Character, but rotated on the X axis
log(camera.position()); // result: {30, 0, 0}

↑ Back to top


screenToWorld(screenPoint)

Converts the given Vec2 screenPoint to a 3D World Position.

Parameters

Vec2 screenPoint – an {x, y} coordinate on the screen

Returns

Vec3 the {x, y, z} 3D world coordinate relative to the given Vec2 screenPoint

function touchMove(point){
  // move an entity to the point where the user is touching the screen.
  let pos = this.scene().camera().screenToWorld(point);
  this.entity().setPosition(pos.x, pos.y, pos.z);
}

↑ Back to top


setFarPlane(value)

Sets the far render distance of the camera. This is the maximum distance from the camera that an object will be rendered.

Parameters

number value – the new far render distance of the camera. Minimum 100.

↑ Back to top


setFieldOfView(value)

This function sets field of view of the camera. The field of view is the extent of the observable world that is seen at any given moment.

Parameters

number value – the field of view, from a range of 10-100. The smaller the number, the more “focused in” your field of view becomes.

↑ Back to top


setFollowThreshold(x, y, z)

Sets the follow threshold of the camera. This determines how far the followed object can get from the camera before it starts moving. Also accepts a Vec3 optionally instead of x, y, z.

Parameters

number x – the x axis component of the follow threshold
number y – the y axis component of the follow threshold
number z – the z axis component of the follow threshold

↑ Back to top


setNearPlane(value)

Sets the Near Render Distance of the camera. This is the minimum distance from the camera that an object will be rendered.

Parameters

number – The Near Render Distance of the camera.

↑ Back to top


setOrthoScale(value)

Sets the orthographic scale of the camera (only works if camera projection is orthographic)

Parameters

number value – the new orthographic scale of the camera

↑ Back to top


setPosition(x, y, z)

Sets the relative position of the camera. It is important to note that if your camera is set to position follow the Character or Path, that will take precedence over a position set with setPosition(). This function will not override a camera’s position in the settings, but adjust the position relative to the original camera position.

Parameters

number x – the relative x axis position
number y – the relative y axis position
number z – the relative z axis position

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.position()); // result: {0, 0, 0}
camera.setPosition(0, 10, 0); // the camera still follows the Character, but 10 units higher
log(camera.position()); // result: {0, 10, 0}

↑ Back to top


setPositionFollow(value)

Sets which object the Camera will follow. There are three options you can pass. “None” – Camera will not follow anything
“Game Path” – Game Path will be followed
“Character” – Any Entity that is considered a Character will be followed

Parameters

string – three possibilities: “None”, “Game Path”, “Character”

↑ Back to top


setProjectionMatrix(matrix)

Sets a custom projection matrix. https://en.wikipedia.org/wiki/Projection_matrix

Parameters

Mat4 matrix – custom projection matrix

↑ Back to top


setRotation(x, y, z)

Sets the relative rotation of the camera. It is important to note that if your camera is set to rotation follow the Character or Path, that will take precedence over a rotation set with setRotation(). This function will not override a camera’s rotation in the settings, but adjust the rotation relative to the original camera rotation.

Parameters

number x – the relative x axis rotation
number y – the relative y axis rotation
number z – the relative z axis rotation

let camera = this.camera();
camera.setPositionFollow("Character");
log(camera.rotation()); // result: {0, 0, 0}, regardless of camera settings
camera.setRotation(30, 0, 0); // the camera still follows the Character, but rotated on the X axis
log(camera.position()); // result: {30, 0, 0}

↑ Back to top


setRotationQuat(value)

Sets the “additional” rotation as quaternion. Note that unlike in Entity, these “setRotation” and “setRotationQuat” are independent, meaning that the result rotation will be a sum of these two.

Parameters

Quaternion value – the new rotation in quaternion

↑ Back to top


setWorldPosition(x, y, z)

Sets the actual position of the camera, the same way it is set in the camera settings panel. If the camera is set to follow position of a character or path, it will act as an offset. Take care when using setWorldPosition and setPosition together, as setPosition sets a relative position based on the camera’s world position.

Parameters

number x – the x-axis component of the new world position
number y – the y-axis component of the new world position
number z – the z-axis component of the new world position

↑ Back to top


worldPosition()

Returns the actual position of the camera. This is the same position as the one set in the camera settings panel.

Returns

Vec3 {x, y, z} position of the camera

↑ Back to top


worldToScreen(x, y, z)

Projects a World (3D) position into Screen (2D) coordinates.

Parameters

number x – the x-axis 3D coordinate
number y – the y-axis 3D coordinate
number z – the z-axis 3D coordinate

Returns

Vec2 the resulting 2D screen coordinates

↑ Back to top

Did you find this page useful?

Please give it a rating:

Please provide some feedback!

This is very helpful to us.