# llWanderWithin

*LSL function*

```lsl
void llWanderWithin(vector origin, vector dist, list options);
```

- `vector origin`: Center coordinate position vector to wander about.
- `vector dist`: A vector specifying the maximum distance limits (half-extents) along each world-aligned axis from the origin.
- `list options`: A list of WANDER_* flags and parameters to configure the wander behavior.

- Energy: 10

Directs a pathfinding character to wander around a central coordinate origin, restricted within the bounding distance limits of dist and configured by options.

Sets a character to wander about a central spot within a specified radius.

```lsl title="How to use" frame="terminal"
llWanderWithin(ZERO_VECTOR, ZERO_VECTOR, []);
```

## Specification

Constant group [CharacterWanderWithinParam](/constants/groups/CharacterWanderWithinParam/):

```lsl
WANDER_PAUSE_AT_WAYPOINTS = 0
```

| Constant | Type | Value | Description |
| --- | --- | --- | --- |
| [WANDER_PAUSE_AT_WAYPOINTS](/constants/WANDER_PAUSE_AT_WAYPOINTS/) | integer | `0` | Whether the character should pause after reaching each wander waypoint. |

<table>
	<tr>
		<th>Option</th>
		<th>V</th>
		<th>Parameters</th>
		<th>Default</th>
		<th>Description</th>
	</tr>
	<tr>
		<td>\[ [integer](https://wiki.secondlife.com/wiki/integer) `boolean` \]</td>
		<td>\[ [FALSE](/constants/FALSE/) \]</td>
		<td>Whether the character should pause after reaching each wander waypoint.</td>
	</tr>
</table>

## Caveats

- Must use [llCreateCharacter](/functions/llCreateCharacter/) or script won't compile.
- Wander area is a rough area based on the specified **origin**, to a specified scale on each axis. So, if `<20, 10, 2>` is specified the object will wander within 20m along the world x-axis, 10m along the world y-axis, and 2m along the world z-axis.
- if **dist** has any dimension less than 1.0, an error is shouted on [DEBUG_CHANNEL](/constants/DEBUG_CHANNEL/). **Scale too small. All dimensions must be at least 1.0.**
- When [WANDER_PAUSE_AT_WAYPOINTS](/constants/WANDER_PAUSE_AT_WAYPOINTS/) is enabled, [PU_GOAL_REACHED](/constants/PU_GOAL_REACHED/) and [PU_SLOWDOWN_DISTANCE_REACHED](/constants/PU_SLOWDOWN_DISTANCE_REACHED/) [path_update](/events/path_update/) events will be trigged when approaching each waypoint. When this flag is disabled, the aforementioned path_update events will not be triggered when arriving at waypoints.
- Wander area can be limited to a smaller area by introducing obstacles such as walls.
- Vertical positions specified for any vectors should be chosen to be as close as possible to the actual height of the terrain requested. Large difference between the provided vertical position and the actual terrain/object will result in failure of the behavior.
- As for all pathfinding behaviors, DO NOT rely on the detailed implementation here. The wander distance is just a rough estimate. We may change the exact shape on a whim. For fun. Or because it seems better that way. Or to ensure that you aren't relying on the detailed implementation. Don't make this another [PATHBUG-69](https://jira.secondlife.com/browse/PATHBUG-69). :)

## Examples

<details open>
<summary>Example 1</summary>

```lsl
default
{
    state_entry()
    {
        llCreateCharacter([CHARACTER_MAX_SPEED, 25, CHARACTER_DESIRED_SPEED, 15.0]);
        //MAX_SPEED is @ 20 by default
    }

    touch_start(integer total_number)
    {
        llWanderWithin(llGetPos(), <10.0, 10.0, 5.0>, [WANDER_PAUSE_AT_WAYPOINTS, TRUE]);
    }
}
```

</details>

## History

Date of Release [31/07/2012](https://wiki.secondlife.com/wiki/Release_Notes/Second_Life_Server/12#12-07-31-262785)

## See also

### Functions

- [llCreateCharacter](/functions/llCreateCharacter/)
- [llDeleteCharacter](/functions/llDeleteCharacter/)
- [llEvade](/functions/llEvade/)
- [llExecCharacterCmd](/functions/llExecCharacterCmd/)
- [llGetClosestNavPoint](/functions/llGetClosestNavPoint/)
- [llFleeFrom](/functions/llFleeFrom/)
- [llNavigateTo](/functions/llNavigateTo/)
- [llPatrolPoints](/functions/llPatrolPoints/)
- [llPursue](/functions/llPursue/)
- [llUpdateCharacter](/functions/llUpdateCharacter/)
- [llWanderWithin](/functions/llWanderWithin/)

### Events

- [path_update](/events/path_update/)

---

*Source: [LlWanderWithin](https://wiki.secondlife.com/wiki/LlWanderWithin) on the Second Life Wiki. Content from the Second Life Wiki articles LlWanderWithin (revision 1216155, 2024-01-28) and Template:LSL Constants/llWanderWithin (revision 1215209, 2023-10-28), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/functions/llWanderWithin/
