# at_target

*LSL event*

```lsl
at_target(integer tnum, vector targetpos, vector ourpos)
```

- `integer tnum`: Integer target handle returned by the llTarget call.
- `vector targetpos`: Target position vector specified in the llTarget call.
- `vector ourpos`: Current position vector of the object (similar to llGetPos).

Triggered when the scripted object's position (ourpos) comes within the defined range of the target position (targetpos) set by llTarget (which returns the associated handle tnum).

Result of [llTarget](/functions/llTarget/) library function call

```lsl title="How to use" frame="terminal"
at_target(integer tnum, vector targetpos, vector ourpos)
{

}
```

## Examples

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

```lsl collapse={1-10, 25-31}
integer target_id;
vector target_pos;

default
{
    state_entry()
    {
        target_pos = llGetPos() + <5.0, 0.0, 0.0>;
        target_id = llTarget(target_pos, 0.5);
        llSetStatus(STATUS_PHYSICS, TRUE);
        llMoveToTarget(target_pos, 0.4);
    }
    at_target(integer tnum, vector targetpos, vector ourpos)
    {
        if (tnum == target_id)
        {
            llOwnerSay("object is within range of target");
            llOwnerSay("target position: " + (string)targetpos + ", object is now at: " + (string)ourpos);
            llOwnerSay("this is " + (string)llVecDist(targetpos, ourpos) + " meters from the target");
            llTargetRemove(target_id);
        }
    }
    not_at_target()
    {
        llOwnerSay(
            "not there yet - object is at " + (string)llGetPos() +
            ", which is " + (string)llVecDist(target_pos, llGetPos()) +
            " meters from the target (" + (string)target_pos + ")"
        );
    }
}
```

</details>

## See also

### Functions

- [llTarget](/functions/llTarget/) — Setup a target position
- [llTargetRemove](/functions/llTargetRemove/) — Stop a target position
- [llRotTarget](/functions/llRotTarget/) — Setup a target rotation
- [llRotTargetRemove](/functions/llRotTargetRemove/) — Stop a target rotation

### Events

- [not_at_target](/events/not_at_target/)
- [at_rot_target](/events/at_rot_target/)
- [not_at_rot_target](/events/not_at_rot_target/)

---

*Source: [At target](https://wiki.secondlife.com/wiki/At_target) on the Second Life Wiki. Content from the Second Life Wiki article At target (revision 1213267, 2023-02-04), CC BY-SA 3.0.*

---

From lsl.dev: https://lsl.dev/events/at_target/
