Jump to content

Only respond to touch event if agent is stood infront of prim


BlackMagi Darkwatch
 Share

You are about to reply to a thread that has been inactive for 4156 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi

Scenario

Agent behind door, cams around the wall and touches the lever and opens the door from the inside. What I would like to achieve is to stop this from happening, in otherwords the agent must be stood infront of the door switch.  I will have no control over the final rotation of the building so I need to take this into account also (and I suck big time at rotations!).

This is what I have at the moment but the float result is always given as postive number so not much help there.

    touch_end(integer total_number)
    {
        if (llDetectedTouchFace(0) == face_number)
        {
            llOwnerSay("Correct face touched...");
            
            //Now to check if the Agent is infront of the prim
            vector my_position = llGetPos();
            vector av_position = llDetectedPos(0);
            
            float test = llVecDist(av_position, my_position);
            llOwnerSay((string)test);   
        }
    }

 I also tried breaking down x,y portions of the vectors but as soon as I rotate my linkset then the results are skewed again.

 If anyone can offer some ideas that would be great

Black

 

Link to comment
Share on other sites

I don't think you will acheive the security you desire this way. You CAN implement using the function that recognizes where on a prim a touch is implemented to make a combination lock. It can also recognize the avatar doing the touching so that perhaps anyone entering the proper pass code would not be ejected from the land.

Link to comment
Share on other sites

For a box prim, each face has one normal
namely: Forward, Left, Up,  -Forward, -Left and -Up

From the top of my head face 0 has Up and face 5 has -Up

Knowing the normal, the prim position and the avatar position
you can use the vector dot product to tell on which side of the prim the avatar is

I will expand your example to do that for face 0:

touch_end(integer total_number){    if (llDetectedTouchFace(0) == 0)    {        llOwnerSay("Correct face touched...");        //Now to check if the Agent is infront of the prim        vector my_position = llGetPos();        vector av_position = llDetectedPos(0);        float test = llVecDist(av_position, my_position);        llOwnerSay((string)test);	float vectorProduct = llRot2Up( llGetRot())*( av_position - my_position);	if ( vectorProduct > 0.0 ) llownerSay("The avatar is in front of the prim");	else llownerSay("The avatar is NOT in front of the prim");    }}

 Note that this is for face 0 exclusively:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

I think the code snippet supplied about Rot2Up is great and works whichever way I rotate the prim within the linkset - there is another optimisation listed on the webpage for llRot2Up so am posting my complete snippet here - this way I can find it in the future!

 

    touch_end(integer total_number)    {        if (llDetectedTouchFace(0) == face_number)        {                vector      my_position = llGetPos();            rotation    my_rotation = llGetRot();            vector      av_position = llDetectedPos(0);            string      av_name     = llGetDisplayName(llDetectedKey(0));                        //Check if the Agent is infront of the prim            float vectorProduct = (<0.0,0.0,1.0> * my_rotation) * (av_position - my_position);                        if ( vectorProduct > 0.0 ) {                //Check to see if the agent is close enough to operate our lever                if (llVecDist(my_position, av_position) > 2.5) { //FALSE                    llWhisper(0, av_name + " Message: To far away");                } else { //TRUE                    llOwnerSay("Message: None: Send Link Messages");                }            } else { //AV is not infront of the prim - let them know                llWhisper(0, av_name + " Message: Can't open");            }        }    }

 

Note: In this snippet I also check to see how far away the toucher is - might not be so elegant but it works :)

 

Thank you to all who replied.

Black

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4156 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...