Jump to content
Wulfie Reanimator

Raycast Visualizer

Recommended Posts

This script is intended to help show exactly where the ray travels and what it hits, if anything.
All you need to do is manually adjust the visualizer's position and rotation using the build tools, and touch the object to "fire" a ray.
The length of the ray can be adjusted by saying any length in local chat, and the visualizer will adjust to it.

To get set up, rez 3 (of any) prims, link them together, and then put this script in. It will create an object like this:

a1202f89d8.png

And here it is in action, hitting the inside of a hollow sphere:

938722ea5e.png

Here's the code:

float length = 5;

default
{
    state_entry()
    {
        // This simply sets up the object properly.
        // Link 1 and 3 are spheres, link 2 is the long cylinder.
        llSetLinkPrimitiveParamsFast(1,[
            9, 3, 0, <0,1,0>, 0.0, <0,0,0>, <0,1,0>,
                18, -1, <0.251,0,1>, 0.5, 7, <0.2,0.2,0.2>,
            34, 2, 33, <0,0,0>, 9, 1, 0, <0,1,0>, 0.0, <0,0,0>, <1,1,0>, <0,0,0>,
                18, -1, <1,0,0.251>, 1, 7, <0.01,0.01,10>, 35, <0.4950,1,0>, 30, 1,
            34, 3, 33, <0,0,0>, 9, 3, 0, <0,1,0>, 0.15, <0,0,0>, <0,1,0>,
                18, -1, <0.251,0,1>, 0.5, 7, <0.2,0.2,0.2>, 30, 1
        ]);
        
        // Only listen to the owner's avatar.
        llListen(0, "", llGetOwner(), "");
    }
    
    listen(integer c, string n, key id, string m)
    {
        // Only react to valid floats.
        if( ((float)(m+"1") == 0.0) ) return;
        
        length = (float)m;
        llSetLinkPrimitiveParamsFast(2, [PRIM_SIZE, <0,0,length*2>]);
        llOwnerSay("New length set.");
    }

    touch_start(integer n)
    {
        // Rotate the end-position of the ray with the object.
        list data = llCastRay( llGetPos(),
            llGetPos() + ((<0,0,length>) * llGetRot()),
            [RC_DATA_FLAGS, RC_GET_ROOT_KEY | RC_GET_LINK_NUM]);
        
        if(llList2Integer(data, -1)) // Was there a hit?
        {
            llOwnerSay("Raycast hit \"" + llKey2Name(llList2Key(data, 0)) +
            "\" link #" + llList2String(data, 1));
            
            // "Dividing" the position with the object's own rotation removes the rotation.
            llSetLinkPrimitiveParamsFast(3,
                [PRIM_POS_LOCAL, (llList2Vector(data, 2) - llGetPos()) / llGetRot()]);
        }
        else
        {
            llOwnerSay("Nothing was hit.");
            llSetLinkPrimitiveParamsFast(3, [PRIM_POS_LOCAL, <0,0,length>]);
        }
    }
}

 

Edited by Wulfie Reanimator
  • Like 4

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...