Environment
Inherits from Instance
Environment is the primary object intended for storing active objects in the place. Objects not inside of the Environment will not be rendered or physically interact with the world.
Not Creatable ServiceSummary
Properties
AutoGenerateNavMesh:boolFogColor:ColorFogEnabled:booleanFogStartDistance:floatFogEndDistance:floatGravity:Vector3=Vector3.NewPartDestroyHeight:floatSkybox:SkyboxPreset
Methods
CreateExplosion:voidOverlapBox:Instance[]OverlapSphere:Instance[]Raycast:RayResultRaycastAll:RayResult[]RebuildNavMesh:voidGetPointOnNavMesh:Vector3
Details
The job of the Environment is to hold objects that exist in the 3D world, effectively Parts. For Parts, this means they will be rendered, and physically interact with other parts and the world. For other objects, it means that they will render.
Understanding this behavior is important, as it means objects can be removed from the Environment when they are not needed. For example, map Models can be removed when a different map is being played on. Objects that are not needed in the 3D world can be stored inside of Hidden or ServerHidden
Accessing the Environment
You use game["Environment"] in order to access the Environment.
Notes
- It is not possible to delete the Environment
- The Environment will automatically clean up Parts that fall beneath PartDestroyHeight
- The client's Camera is stored under the environment and can be accessed via
game["Environment"]["Camera"] - You can set the fog of the world under the Environment properties
- You can set the Skybox of the world under the Environment properties
Properties
AutoGenerateNavMesh
Environment.AutoGenerateNavMesh: bool
Determines whether or not to automatically build a navigation mesh for NPC pathfinding. This property is disabled by default so there are no performance issues with larger maps.
Environment:BuildNavMesh() method.FogColor
Environment.FogColor: Color
The color of the fog. Fog is a visual effect that makes the world look like it is covered in a colored mist.
Example
Change the fog color to white:
game["Environment"].FogColor = Color.New(1, 1, 1, 1)
FogEnabled
Environment.FogEnabled: boolean
Whether or not fog is enabled.
FogStartDistance
Environment.FogStartDistance: float
The distance from the camera at which fog starts to appear
FogEndDistance
Environment.FogEndDistance: float
The distance from the camera at which fog is fully opaque
Gravity
Environment.Gravity: Vector3=Vector3.New
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
0 | any | - | |
-75 | any | - | |
0 | any | - |
The direction and strength of gravity in the world
PartDestroyHeight
Environment.PartDestroyHeight: float
The height at which unanchored parts are destroyed when they fall below it.
Example
game["Environment"].PartDestroyHeight = -2000
Skybox
Environment.Skybox: SkyboxPreset
The default skybox preset to use for the world, if no ImageSky is present.
Methods
CreateExplosion
Environment:CreateExplosion(Position: Vector3, Radius: float, Force: float, affectAnchored: bool, callback: function, damage: float)
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
Position | Vector3 | - | |
Radius | float | 10 | |
Force | float | 5000 | |
affectAnchored | bool | true | |
callback | function | nil | |
damage | float | 10000 |
Creates a deadly explosion killing players and applying force to parts at the given position.
Example
game["Environment"]:CreateExplosion(Vector3.New(0, 0, 0), 30, 5000, false, nil, 10)
OverlapBox
Environment:OverlapBox(position: Vector3, size: Vector3, rotation: Vector3, ignoreList: array): Instance[]
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
position | Vector3 | - | |
size | Vector3 | - | |
rotation | Vector3 | - | |
ignoreList | array | Instance[] |
Returns a list of instances intersecting with the box in the given position, size and rotation.
A demo of this method is available here.
Example
local intersections = game["Environment"]:OverlapBox(Vector3.New(0,0,0), Vector3.New(2,2,3), Vector3.New(0,0,0))
for i,v in ipairs(intersections) do
print(v.Name .." is intersecting the box!")
end
OverlapSphere
Environment:OverlapSphere(position: Vector3, radius: float, ignoreList: array): Instance[]
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
position | Vector3 | - | |
radius | float | - | |
ignoreList | array | Instance[] |
Returns a list of instances intersecting with the sphere in the given position and radius.
Example
local intersections = game["Environment"]:OverlapSphere(Vector3.New(100,0,45), 25)
for i,v in ipairs(intersections) do
print(v.Name .." is intersecting the sphere!")
end
Raycast
Environment:Raycast(origin: Vector3, direction: Vector3, maxDistance: float, ignoreList: array): RayResult
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
origin | Vector3 | - | |
direction | Vector3 | - | |
maxDistance | float | infinite | |
ignoreList | array | Instance[] |
Casts a ray from origin with a specified direction and returns a RayResult for the first hit object.
Example
local hit = game["Environment"]:Raycast(barrel.Position, barrel.Forward)
if hit and hit.Instance:IsA("Player") then
hit.Instance.Health = 0
end
RaycastAll
Environment:RaycastAll(origin: Vector3, direction: Vector3, maxDistance: float, ignoreList: array): RayResult[]
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
origin | Vector3 | - | |
direction | Vector3 | - | |
maxDistance | float | infinite | |
ignoreList | array | Instance[] |
Casts a ray from origin with a specified direction and returns a RayResult array for all hit objects.
Example
local hits = game["Environment"]:RaycastAll(Vector3.New(0, 10, 0), Vector3.New(0, -1, 0), 100)
for i, hit in pairs(hits) do
print("Hit at " .. hit.Position .. "!")
end
RebuildNavMesh
Environment:RebuildNavMesh(root: Instance)
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
root | Instance | nil |
Rebuilds the navigation mesh which determines the empty space where NPCs can pathfind in.
Example
game["Environment"]:RebuildNavMesh()
# or
game["Environment"]:RebuildNavMesh(game["Workspace"]["Map"])
GetPointOnNavMesh
Environment:GetPointOnNavMesh(position: Vector3, maxDistance: float): Vector3
Parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
position | Vector3 | - | |
maxDistance | float | infinite |
Returns a point on the navigation mesh at the given position.