Jump to content

---SOLVED--- Touch_start Range?


LouiseDeBlois
 Share

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

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

Recommended Posts

Hi, i would like to know how i can make an object, ONLY be clicked, or touched, when a player is standing close.

 

So far I am using:

 

// Rez an object on touch, with relative position, rotation, and velocity all described in the rezzing prim's coordinate system.
string object = "Log"; // Name of object in inventory
vector relativePosOffset = <0.0, 0.0, 2.0>; // "Forward" and a little "above" this prim
vector relativeVel = <0.0, 0.0, 0.0>; // Traveling in this prim's "forward" direction at 1m/s
rotation relativeRot = <0.707107, 0.0, 0.0, 0.707107>; // Rotated 90 degrees on the x-axis compared to this prim
integer startParam = 10;
 
default
{
    touch_start(integer a)
    {
        vector myPos = llGetPos();
        rotation myRot = llGetRot();
 
        vector rezPos = myPos+relativePosOffset*myRot;
        vector rezVel = relativeVel*myRot;
        rotation rezRot = relativeRot*myRot;
 
        llRezObject(object, rezPos, rezVel, rezRot, startParam);
    }
}

 How can i impliment this so it works when someone is close? as in.... Has to be near the object to click it. 

 

or the

 

"To far to access this" "to far to interact" Reply?

Link to comment
Share on other sites

Try something like this, using llVecDist

float MaxDist = 3.0;string dist;default{    state_entry()    {        dist = llGetSubString((string)MaxDist,0,(llSubStringIndex((string)MaxDist,".")+2));       // llOwnerSay(dist);    }    touch_start(integer total_number)    {         key k = llDetectedKey(0);        vector pos = llGetPos();        if(llVecDist(pos,llDetectedPos(0))>MaxDist){            llRegionSayTo(k,0,"Sorry, "+llGetDisplayName(k)+" but you must be no more than "+dist+" metres away for this to work");            return;        }        else{          llRegionSayTo(k,0,"You are within the maximum range");          //do stuff        }            }}

 

Link to comment
Share on other sites

ETA -- Congratulations!  You fixed it as I was typing this.

It's very simple to combine them.

In the code you've posted, you have several global variables declared, -- string object, vector relativePosOffset and so on.

I've added two more, float MaxDist and string dist.   So just put all the global variables together, up at the top, before default.

Then use state_entry to calculate the value of dist, like this

// Rez an object on touch, with relative position, rotation, and velocity all described in the rezzing prim's coordinate system.string object = "Log"; // Name of object in inventoryvector relativePosOffset = <0.0, 0.0, 2.0>; // "Forward" and a little "above" this primvector relativeVel = <0.0, 0.0, 0.0>; // Traveling in this prim's "forward" direction at 1m/srotation relativeRot = <0.707107, 0.0, 0.0, 0.707107>; // Rotated 90 degrees on the x-axis compared to this priminteger startParam = 10;float MaxDist = 3.0;// 3 metres -- put in whatever you wantstring dist; // this is just cosmetic, so the chat looks nicerdefault{	state_entry()	{		dist = llGetSubString((string)MaxDist,0,(llSubStringIndex((string)MaxDist,".")+2));		// turn the float into a string, comprising the value of the float to 2 decimal places (otherwise it's going to say "3.000000", which looks silly)	}}

 In the touch_start event, I've just added the test to see where the toucher is.   If the toucher is too far away, you tell her and then stop.  Otherwise, you go on and do it.   So that  bit would look like 

 

touch_start(integer total_number)	{		vector pos = llGetPos();		key k = llDetectedKey(0);		if(llVecDist(pos,llDetectedPos(0))>MaxDist){// if the distance between the toucher's position and my position is more than MaxDist				llRegionSayTo(k,0,"Sorry, "+llGetDisplayName(k)+" but you must be no more than "+(string)MaxDist+" metres away for this to work");//say so			return;//and do nothing else		}		else{//if we have got this far, the toucher must be in range, so go and rez things			rotation myRot = llGetRot();			vector rezPos = myPos+relativePosOffset*myRot;			vector rezVel = relativeVel*myRot;			rotation rezRot = relativeRot*myRot;			llRezObject(object, rezPos, rezVel, rezRot, startParam);		}	}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4141 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...