ItHadToComeToThis Posted January 29 Share Posted January 29 (edited) So, I wrote this script and for some reason it's detecting everyone else....except for me....and I have tried to test everything from individual positions greater and lesser than the X and Y object position. And it just will not detect me. Can someone take a look and lemme know what im missing here. Im having one of those blind moments. I was trying to make it scan within the confines of a prim, regardless of how the prim is sized on the X and Y, restricted to within the prims boundaries. vector scale; float range; findRange(vector s){ if(s.x>s.y){ range=s.x; }else if(s.x<s.y){ range=s.y; }else{ range=s.x; } range/=2.0; } default{ state_entry(){ scale=llGetScale(); findRange(scale); llSensorRepeat("","",AGENT_BY_LEGACY_NAME,range,PI,60.0); } on_rez(integer param){ llResetScript(); } changed(integer x){ if(x&CHANGED_SCALE){ llSensorRemove(); scale=llGetScale(); findRange(scale); //llOwnerSay("Range is: "+(string)range); llSensorRepeat("","",AGENT_BY_LEGACY_NAME,range,PI,60.0); } } sensor(integer num){ integer i=-1; while(++i<num){ //llOwnerSay(llKey2Name(llDetectedKey(i))); vector avPos=llList2Vector(llGetObjectDetails(llDetectedKey(i),[OBJECT_POS]),0); vector objPos=llGetPos(); if(avPos.x<(objPos.x+(scale.x/2.0))&&avPos.x>(objPos.x-(scale.x/2.0))&&avPos.y<(objPos.y+(scale.y/2.0))&&avPos.y>(objPos.y-(scale.y/2.0))){ llOwnerSay("Ask "+llKey2Name(llDetectedKey(i))+" for hud balance"); } } } } Edited January 29 by ItHadToComeToThis 1 Link to comment Share on other sites More sharing options...
elleevelyn Posted January 29 Share Posted January 29 i had a quick play with the script. It detects me ok when I am within sensor range. It doesn't detect me when I am in a corner of the box where the sensor being a sphere, doesn't reach when working with sensing agent presence inside a box then the sensor sphere is best to encompass the entire box, which we can do by setting the sensor range (radius) to half the diagonal of the box. And then checking for agent position inside the box, so that any agent detected outside the box is excluded some longhand example functions which show a way this can be done (assumes script is in the box prim) float getBoxHalfDiagonal() { // return half the box diagonal vector pos = llGetPos(); vector scale = llGetScale() * 0.5; vector topcorner = pos + scale; vector bottomcorner = pos - scale; return llVecDist(topcorner, bottomcorner) * 0.5; } integer isInBox(vector position) { // is position inside the box ? vector pos = llGetPos(); vector scale = llGetScale() * 0.5; vector topcorner = pos + scale; vector bottomcorner = pos - scale; return (position.x <= topcorner.x) & (position.x >= bottomcorner.x) & (position.y <= topcorner.y) & (position.y >= bottomcorner.y) & (position.z <= topcorner.z) & (position.z >= bottomcorner.z); } default { ... set sensor range to getBoxHalfDiagonal sensor(integer detected) { integer yes = isInBox(llDetectedPos(...)); } } 1 Link to comment Share on other sites More sharing options...
ItHadToComeToThis Posted January 30 Author Share Posted January 30 Thank you muchly! 1 Link to comment Share on other sites More sharing options...
Lucia Nightfire Posted January 30 Share Posted January 30 Don't forget to bulletproof it in case the box is rotated. 😉 1 Link to comment Share on other sites More sharing options...
elleevelyn Posted January 30 Share Posted January 30 1 hour ago, Lucia Nightfire said: Don't forget to bulletproof it in case the box is rotated. 😉 true this Link to comment Share on other sites More sharing options...
Recommended Posts
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