Skip to content

llWorldPosToHUD

vector llWorldPosToHUD(vector world_pos)

Returns the local position that would put the origin of a HUD object directly over world_pos as viewed by the current camera.

Parameters
world_pos (vector)
The world-frame position to project into HUD space
  • 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
// llWorldPosToHUD() example
//
// Put this script on a HUD attachment (which attachment point doesn't matter).
// 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)
{
// 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);
}
}
}