Skip to content
lsl.devlsl.devLSL Dev

llWorldPosToHUD

function
Function syntax
vector llWorldPosToHUD(
  1. vector world_pos// World-frame position vector to project into HUD space.
);
Returns
vector
Energy
10

Returns the local position vector that places the center of the HUD object directly over the world coordinate world_pos as viewed by the current camera. Requires the PERMISSION_TRACK_CAMERA runtime permission.

Returns a vector position in HUD frame that would place the center of the HUD object directly over world_pos as viewed by the current camera.

How to use
vector result = llWorldPosToHUD(ZERO_VECTOR);

Only works for HUD attachments. The vector’s X component will be 1.0 when world_pos is in front of camera and -1.0 when it is behind. Returns zero vector when no permissions have been granted.

Example 1
// llWorldPosToHUD() example
//
// Put this script on a HUD attachment (which attachment point doesn't matter).
50 collapsed lines
// Touch to toggle 'tracking' on/off.
// Put an object at world_pos as reference for where the HUD should move when 'tracking'.
vector not_tracking_color = <1.0, 1.0, 1.0>; // white
vector tracking_front_color = <0.5, 0.0, 0.5>; // magenta
vector tracking_behind_color = <0.0, 0.5, 0.5>; // cyan
vector world_pos = <32,32,24>; // change this position as necessary, put a ref object here
integer tracking = FALSE;
default
{
state_entry()
{
llOwnerSay("Touch HUD to toggle tracking");
llRequestPermissions(llGetOwner(), PERMISSION_TRACK_CAMERA);
llSetAlpha(0.5, ALL_SIDES); // make object semi transparent
llSetColor(not_tracking_color, ALL_SIDES);
}
touch_start(integer total_number)
{
llRequestPermissions(llGetOwner(), PERMISSION_TRACK_CAMERA);
tracking = !tracking;
if (tracking)
{
llSetTimerEvent(0.01);
llSetColor(tracking_front_color, ALL_SIDES);
}
else
{
llSetTimerEvent(0.0);
llSetPos(<0,0,0>);
llSetColor(not_tracking_color, ALL_SIDES);
}
}
attach(key id)
{
if (id != NULL_KEY)
{
llSetPos(<0,0,0>);
tracking = FALSE;
llSetTimerEvent(0.0);
}
}
timer()
{
integer attachment_point = llGetAttached();
if (attachment_point >= ATTACH_HUD_CENTER_2 && attachment_point <= ATTACH_HUD_BOTTOM_RIGHT)
{
vector hud_pos = llWorldPosToHUD(world_pos);
if (hud_pos.x > 0.0)
{
13 collapsed lines
// world-pos is in front of camera
llSetColor(tracking_front_color, ALL_SIDES);
}
else
{
// world_pos is behind camera
llSetColor(tracking_behind_color, ALL_SIDES);
}
// update HUD position
llSetPos(hud_pos);
}
}
}
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.

From the Second Life Wiki

Community documentation adapted from LlWorldPosToHUD, by Linden Research, Inc. and contributing residents.View contributors and history.

Imported wiki revision:

Licensed under CC BY-SA 3.0. Last wiki edit: .Formatting and links have been adapted for this site; API metadata follows the LSL definitions.