Skip to main content

Environment

Contains functions to customize and control the world environment.

info

This module can only be used in Entity scripts.

Properties

skyColor

Color of the upper half of the skybox. This property is read-only.

equatorColor

Color of the middle area of the skybox. This property is read-only.

groundColor

Color of the lower half of the skybox. This property is read-only.

sunColor

Color of the sun's lighting. This property is read-only.

fogNearColor

Color of fog at the start of the effect. This property is read-only.

fogFarColor

Color of fog at the end of the effect. This property is read-only.

backgroundPrimaryColor

Primary color of the background. This property is read-only.

backgroundSecondaryColor

Secondary color of the background. This property is read-only.

equatorHeight

Range of the equator color. This property is read-only.

skyboxOffset

Vertical displacement of the equator color. This property is read-only.

fogStart

Distance where fog effect starts. This property is read-only.

fogEnd

Distance where the fog effect is most noticeable. This property is read-only.

fogIntensity

Intensity of the fog effect. This property is read-only.

cloudsSpeed

How fast the clouds in the sky move. This property is read-only.

cloudsLightColor

Color of the upper part of clouds. This property is read-only.

cloudsShadowColor

Color of the lower part of clouds. This property is read-only.

starsIntensity

Quantity and brightness of skybox stars. This property is read-only.

sunIntensity

Intensity of lighting from the sun. This property is read-only.

cloudsIntensity

Visibility of clouds. This property is read-only.

ambientIntensity

Passive lighting intensity. This property is read-only.

sunAngle

Vertical position of the sun. Affects time of day. This property is read-only.

sunRotation

Horizontal position of the sun. This property is read-only.

backgroundPrimaryColorIntensity

Intensity of the primary background color. This property is read-only.

backgroundSecondaryColorIntensity

Intensity of the secondary background color. This property is read-only.

hideBottomStars

Toggle for the appearance of stars under the world. Stored as a number. This property is read-only.

worldBorderVisible

Toggle for the visibility of a red grid at the edge of the world. Stored as a number. This property is read-only.

Functions

setSkyColor(color)

Sets skybox main color.

Parameters

  • color Color. Alpha will be ignored.

Example

Set sky color to red.

function onStart()
local red = Color.new(255,0,0)
Environment.setSkyColor(red)
end

setEquatorColor(color)

Sets skybox equator color.

Parameters

  • color Color. Alpha will be ignored.

Example

Set equator color to green.

function onStart()
local green = Color.new(0,255,0)
Environment.setEquatorColor(green)
end

setGroundColor(color)

Sets skybox ground color.

Parameters

  • color Color. Alpha will be ignored.

Example

Set ground color to yellow.

function onStart()
local yellow = Color.new(255,255,0)
Environment.setGroundColor(yellow)
end

setSunColor(color)

Sets sun color. This also sets color of the light.

Parameters

  • color Color. Alpha will be ignored.

Example

Set Sun color to purple.

function onStart()
local purple = Color.new(128,0,128)
Environment.setSunColor(purple)
end

setFogNearColor(color)

Sets fog starting color.

Parameters

  • color Color. Alpha controls fog density.

Example

Set fog near color to orange.

function onStart()
local orange = Color.new(255,165,0)
Environment.setFogNearColor(orange)
end

setFogFarColor(color)

Sets fog end color.

Parameters

  • color Color. Alpha controls fog density.

Example

Set fog far color to gray.

function onStart()
local gray = Color.new(128,128,128)
Environment.setFogFarColor(gray)
end

setBackgroundPrimaryColor(color, intensity)

Sets current background primary color.

Parameters

  • color Color. Alpha will be ignored.
  • intensity HDR intensity of the color.
    • Min: -15
    • Max: 15

Example

Set background primary color to pink.

function onStart()
local pink = Color.new(255,192,203)
Environment.setBackgroundPrimaryColor(pink,1)
end

setBackgroundSecondaryColor(color, intensity)

Sets current background secondary color.

Parameters

  • color Color. Alpha will be ignored.
  • intensity HDR intensity of the color.
    • Min: -15
    • Max: 15

Example

Set background secondary color to brown.

function onStart()
local brown = Color.new(165,42,42)
Environment.setBackgroundSecondaryColor(brown,1)
end

setEquatorHeight(height)

Sets equator height. Represents the height of the gradient between skyColor and equatorColor.

Parameters

  • height Value in range [0, 1].
    • Min: 0
    • Max: 1

Example

Set equator gradient heigth halfway between skyColor and equatorColor.

function onStart()
Environment.setEquatorHeight(0.5)
end

setSkyboxOffset(offset)

Sets skybox offset. Represents the equator point. Default is 0.

Parameters

  • offset Value in range [-1, 1].
    • Min: -1
    • Max: 1

Example

Set skybox offset to 1. This will hide the Sun (night).

function onStart()
Environment.setSkyboxOffset(1)
end

setFogStart(fogStart)

Sets start distance of the fog.

Parameters

  • fogStart Any positive number.

Example

Set the start distance of the fog to 5.

function onStart()
Environment.setFogStart(5)
Environment.setFogEnd(10)
end

setFogEnd(fogEnd)

Sets end distance of the fog.

Parameters

  • fogEnd Any positive number. Can't be lower than start distance.

Example

Set the end distance of the fog to 5 (fog start has to be less than 5).

function onStart()
Environment.setFogStart(1)
Environment.setFogEnd(5)
end

setFogIntensity(fogIntensity)

Sets fill (density) of the fog.

Parameters

  • fogIntensity Value in range [0, 1].
    • Min: 0
    • Max: 1

Example

Set the fog intensity to its maximum value.

function onStart()
Environment.setFogIntensity(1)
end

setStarsIntensity(intensity)

Sets intensity of the stars. 0 will hide the stars completely.

Parameters

  • intensity Value in range [0, 5].
    • Min: 0
    • Max: 5

Example

Set stars intensity to 3.

function onStart()
Environment.setStarsIntensity(3)
end

setSunIntensity(intensity)

Sets intensity of the sun. This controls the brightness of the sun visual and the light intensity.

Parameters

  • intensity Value in range [0, 5].
    • Min: 0
    • Max: 5

Example

Set Sun intensity to 0. This will make everything spooky and dark.

function onStart()
Environment.setSunIntensity(0)
end

setCloudsIntensity(intensity)

Sets intensity (transperency) of the clouds. 0 will hide clouds completely.

Parameters

  • intensity Value in range [0, 1].
    • Min: 0
    • Max: 1

Example

Set clouds intensity to 0. This will hide the clouds.

function onStart()
Environment.setCloudsIntensity(0)
end

setCloudsSpeed(speed)

Sets the speed of the clouds.

Parameters

  • speed Number for cloud speed.

Example

Set clouds speed to 10.

function onStart()
Environment.setCloudsSpeed(10)
end

setCloudsLightColor(color)

Sets the color for the upper part of clouds.

Parameters

  • color Color. Alpha will be ignored.

Example

Set cloud light color to red.

function onStart()
Environment.setCloudsLightColor(Color.red)
end

setCloudsShadowColor(color)

Sets the color for the lower part of clouds.

Parameters

  • color Color. Alpha will be ignored.

Example

Set cloud shadow color to green.

function onStart()
Environment.setCloudsShadowColor(Color.green)
end

setAmbientIntensity(intensity)

Sets intensity of ambient light. This light is additional to the sunlight and lights object from all directions.

Parameters

  • intensity Value in range [0, 1].
    • Min: 0
    • Max: 1

Example

Set intensity of ambient light to 1. This will make everything visible even if there is no sun light.

function onStart()
Environment.setAmbientIntensity(1)
end

setSunAngle(angle)

Sets the angle of the sun.

Parameters

  • angle Value in range [0, 360]. For daytime 0 - 180 for nighttime 181 - 360.
    • Min: 0
    • Max: 360

Example

Set the sun angle to 70 degrees.

function onStart()
Environment.setSunAngle(70)
end

setSunRotation(angle)

Sets the rotation of the sun.

Parameters

  • angle Value in range [0, 360].
    • Min: 0
    • Max: 360

Example

Set the sun rotation to 70 degrees.

function onStart()
Environment.setSunRotation(70)
end

setBottomStars(enabled)

Enables or disables stars on the bottom part of the skybox.

Parameters

  • enabled True or false to toggle bottom stars.

Example

Disable stars on the bottom part of the skybox.

function onStart()
Environment.setBottomStars(false)
end

setBorderVisible(enabled)

Sets the visibility of the red grid at the edge of the world.

Parameters

  • enabled True or false to toggle bound visibility.

Example

Hide the world border.

function onStart()
Environment.setBorderVisible(false)
end

set(properties)

Sets environment parameters in bulk.

Parameters

Example

Set the sky completly red with a sun intensity of 3.

function onStart()
local red = Color.new(255,0,0)
local redSky = {
skyColor = red,
equatorColor = red,
groundColor = red,
sunColor = red,
sunIntensity = 3
}
Environment.set(redSky)
end

transition(properties, time, asyncMode)

Sets environment parameters in bulk over time.

Parameters

  • properties EnvironmentConfig with parameters to override.
  • time Time in seconds.
  • asyncMode The AsyncMode which determines whether the task should wait for the function to complete before continuing.

Example

Set a smooth 3 seconds transition between a red sky and a purple sky.

function onStart()
local red = Color.new(255,0,0)
local purple = Color.new(128,0,128)
local redSKy = {
skyColor = red,
equatorColor = red,
groundColor = red,
sunColor = red,
sunIntensity = 3
}
local purpleSky = {
skyColor = purple,
equatorColor = purple,
groundColor = purple,
sunColor = purple,
sunIntensity = 1
}
Environment.set(redSky)
Environment.transition(purpleSky, 3)
end