Skip to main content

Surroundings

A Types.Sense that casts a ring of rays and writes the nearest obstacle and the most open direction. Distances are math.huge when there is nothing to measure.

Types​

SurroundingsOptions​

interface SurroundingsOptions {
Rays: number?--

Rays around the agent, evenly spaced. Default 8.

Distance: number?--

Reach of each ray in studs. Default 12.

Height: number?--

Added to the agent's root position for the cast origin. Default 0.

Ignore: ((agent: Agent) → {Instance})?--

Instances the rays pass through, on top of the agent's own entity, which always is.

Prefix: string?--

Prepended to every key this sense writes, so two instances can coexist. Default "".

}

Functions​

Directions​

Surroundings.Directions(count: number) → {Vector3}--

count unit directions around Y: forward (-Z), then left, back, right.

Pure.

Evaluate​

Surroundings.Evaluate(
directions: {Vector3},--

From Surroundings.Directions, rotated to the agent's facing.

distances: {number?},--

Hit distance per direction, nil for a clear ray.

reach: number--

The rays' reach, what a clear ray counts as.

) → {
ObstacleDistance: number,
ObstacleDirection: Vector3?,
OpenDirection: Vector3,
OpenDistance: number
}

Summarises a ring of results. Pure.

new​

Surroundings.new(options: SurroundingsOptions?) → Sense

Tick​

Surroundings.Tick(
self: SurroundingsClass,
agent: Agent,
deltaTime: number
) → ()

Destroy​

Surroundings.Destroy(self: SurroundingsClass) → ()

Nothing to release.

Configure​

Surroundings.Configure(
self: SurroundingsClass,
patch: SurroundingsOptions--

The options to change; the rest keep their values.

) → ()

Changes options after construction, for difficulty and pacing: a director widening the cone or shortening the memory mid-round. The same rules as new apply.

Errors

TypeDescription
"unknown option"
Show raw api
{
    "functions": [
        {
            "name": "Directions",
            "desc": "Pure.",
            "params": [
                {
                    "name": "count",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "`count` unit directions around Y: forward (-Z), then left, back, right.",
                    "lua_type": "{ Vector3 }"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 84,
                "path": "lib/Senses/Surroundings.luau"
            }
        },
        {
            "name": "Evaluate",
            "desc": "Summarises a ring of results. Pure.",
            "params": [
                {
                    "name": "directions",
                    "desc": "From [Surroundings.Directions], rotated to the agent's facing.",
                    "lua_type": "{ Vector3 }"
                },
                {
                    "name": "distances",
                    "desc": "Hit distance per direction, `nil` for a clear ray.",
                    "lua_type": "{ number? }"
                },
                {
                    "name": "reach",
                    "desc": "The rays' reach, what a clear ray counts as.",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "{ ObstacleDistance: number, ObstacleDirection: Vector3?, OpenDirection: Vector3, OpenDistance: number }"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 102,
                "path": "lib/Senses/Surroundings.luau"
            }
        },
        {
            "name": "new",
            "desc": "",
            "params": [
                {
                    "name": "options",
                    "desc": "",
                    "lua_type": "SurroundingsOptions?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Sense"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 144,
                "path": "lib/Senses/Surroundings.luau"
            }
        },
        {
            "name": "Tick",
            "desc": "",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "SurroundingsClass"
                },
                {
                    "name": "agent",
                    "desc": "",
                    "lua_type": "Agent"
                },
                {
                    "name": "deltaTime",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 164,
                "path": "lib/Senses/Surroundings.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Nothing to release.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "SurroundingsClass"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 203,
                "path": "lib/Senses/Surroundings.luau"
            }
        },
        {
            "name": "Configure",
            "desc": "Changes options after construction, for difficulty and pacing: a director widening the cone\nor shortening the memory mid-round. The same rules as `new` apply.",
            "params": [
                {
                    "name": "self",
                    "desc": "",
                    "lua_type": "SurroundingsClass"
                },
                {
                    "name": "patch",
                    "desc": "The options to change; the rest keep their values.",
                    "lua_type": "SurroundingsOptions"
                }
            ],
            "returns": [],
            "function_type": "static",
            "errors": [
                {
                    "lua_type": "\"unknown option\"",
                    "desc": ""
                }
            ],
            "source": {
                "line": 215,
                "path": "lib/Senses/Surroundings.luau"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "SurroundingsOptions",
            "desc": "",
            "fields": [
                {
                    "name": "Rays",
                    "lua_type": "number?",
                    "desc": "Rays around the agent, evenly spaced. Default `8`."
                },
                {
                    "name": "Distance",
                    "lua_type": "number?",
                    "desc": "Reach of each ray in studs. Default `12`."
                },
                {
                    "name": "Height",
                    "lua_type": "number?",
                    "desc": "Added to the agent's root position for the cast origin. Default `0`."
                },
                {
                    "name": "Ignore",
                    "lua_type": "((agent: Agent) -> { Instance })?",
                    "desc": "Instances the rays pass through, on top of the agent's own entity, which always is."
                },
                {
                    "name": "Prefix",
                    "lua_type": "string?",
                    "desc": "Prepended to every key this sense writes, so two instances can coexist. Default `\"\"`."
                }
            ],
            "source": {
                "line": 44,
                "path": "lib/Senses/Surroundings.luau"
            }
        }
    ],
    "name": "Surroundings",
    "desc": "A [Types.Sense] that casts a ring of rays and writes the nearest obstacle and the most open\ndirection. Distances are `math.huge` when there is nothing to measure.",
    "source": {
        "line": 76,
        "path": "lib/Senses/Surroundings.luau"
    }
}