This is my first post and I'm still relatively new with SL scripts, so please forgive me if I made any glaring errors that only a noob can make.
What I am trying to accomplish here is a HUD "targeting reticle" that will always float over the closest avatar within radar range. However, the results have been largely inaccurate, especially when moving further away from the avatar. I suspect it's a logic problem, but my maths isn't the best in class and my brain cells are fried already. =(
Kindly help me out with the following script I have put together. This goes into a prim that is attached to the HUD.
CODE
//--------------------------------
//adjust sensor setting
float sensor_dist=95;
float sensor_time=1.0;
//--------------------------------
integer x=0;
float dist=0;
vector ownervector;
vector avatarvector;
vector displayvector;
default
{
state_entry()
{
llSensorRepeat("",NULL_KEY,AGENT,sensor_dist,PI,sensor_time);
llRequestPermissions(llGetOwner(), PERMISSION_TRACK_CAMERA);
}
sensor(integer total_number)
{
for(x=0;x<1;x++)
{
if(llDetectedName(x) == "00000000-0000-0000-0000-000000000000") { jump getout;}
if(llDetectedKey(x) != llGetOwner())
{
if (x==0)
{
llSetText(llDetectedName(x),<0,1,0>,1);
}
avatarvector = llDetectedPos(x);
ownervector = llGetCameraPos();
displayvector = (avatarvector-ownervector);
displayvector = displayvector/llGetCameraRot();
displayvector.z = displayvector.z*0.09;
displayvector.y = displayvector.y*0.09;
displayvector.x = 0;
llSetPos(displayvector);
}
}
@getout;
}
no_sensor()
{
llSetText("No Agents Detected",<0,1,0>,1);
llSetPos(<0,0,0>);
}
}
Any help or advice will be greatly appreciated!
;