Jump to content

Distance Meter


Xi Leung
 Share

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

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

Recommended Posts

When you write your script, use llSensorRepeat to drive a sensor that looks for the second object.  Then in your sensor event all you need to write is

llOwnerSay("Object 2 is " + (string) llVecDist(llGetPos() - llDetectedPos(0)) + "m away.");

If you only want the message when the distance between the objects changes, then store the result each time the sensor fires and compare it with the new result the next time it fires.  Incidentally, this will only work if the objects are within 96m of each other, but there are other ways of getting the position of a more distant object.

 

Link to comment
Share on other sites

Thank you Rolig for the help

It is a very good idea to make the script work only when the distance or any position changes (no lag, no spam messages). A 96 meter radius is actually fine, but the more we get the better.

I think I've seen a distance script in the older Forum - made by you guessed. However I cannot find it :(

 

 

 

 

 

 

Link to comment
Share on other sites

Well, you can avoid unnecessary messages easily enough, but you can't avoid at least some lag.  It's just a question of what is creating the lag. You can try using a completely different approach from what I suggested before to see.  Put a tiny script with a timer in Object 2 that checks the object's position periodically and

llRegionSay(-12345, (string) llGetPos())

whenever it moves to a new spot.  Then write your main script to listen for the message and

if (llGetPos() != my_own_old_stored_position)

{

     llOwnerSay("Object 2 is " + (string)llVecDist(llGetPos() - object_2_stored_position)  + "m away");

    my_own_stored_position = llGetPos();

}

else if ( (vector)gMessage != object_2_stored_position)

{

     llOwnerSay("Object 2 is " + (string)llVecDist(llGetPos() - (vector) gMessage)  + "m away");

     object_2_stored_position = (vector)gMessage;

}

The timer in each script will still contribute a little lag to the sim, and you will have increased the sim's script overhead slightly by running two scripts instead of one, but you won't have a sensor firing all the time.  Frankly, I don't know which option is friendlier to the sim but I can't imagine that either is much to worry about.

Link to comment
Share on other sites

You could do it with just one timer, I think.

Have the monitoring unit acquire the target's uuid by using a sensor or a listen when you initially set the system up, and then have the monitor periodically check

llList2Vector(llGetObjectDetails(target,[OBJECT_POS]),0)

No need for the object whose position we're tracking to do anything after the monitor's grabbed its uuid, I think.

Link to comment
Share on other sites

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