Does anyone have an avatar watcher script?
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
02-23-2009 06:43
Does anyone have a script that will cause an object to rotate on it's z-axis, so that it always faces the nearest av? It needs to have a long range too, because it is a big object. I have a script that causes the object to rotate around all 3 axis and face the av, but I only want it to rotate around the z and I cannot figure out how to resrict it to just that. I am a tyro in LSL so I apologise if the answer seems obvious to those of you with more experience. Any assistance appreciated. Thanks 
|
|
Innula Zenovka
Registered User
Join date: 20 Jun 2007
Posts: 1,825
|
02-23-2009 07:25
Try putting llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE); in your script's state_entry() somewhere. Not sure it'll do what you want, but it should stop the object from rotating round the x and y axes. See http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetStatus
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
02-23-2009 08:09
Thanks for that Innula. I am off to try it now 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-23-2009 09:01
That is definitely the simplest, easiest solution. If for some reason that isn't sufficient, you could use logic similar to the following to calculate a suitable rotation. Assuming the object's "forward" direction is its local x-axis: facePosition(vector pos, float rotStrength, float rotTau) { vector posOffset = pos-llGetPos(); if (llFabs(posOffset.z) > 0.999) { // Straight up/down. Any direction should do. return; }
vector localY = llVecNorm(<0.0, 0.0, 1.0>%posOffset); vector localX = localY%<0.0, 0.0, 1.0>; // Already a unit vector
rotation rot = llAxes2Rot(localX, localY, <0.0, 0.0, 1.0>);
llRotLookAt(rot, rotStrength, rotTau); }
There's a small optimization that can be done for the cross products in this case, but I think it is slightly more understandable as written above so I'll leave the optimization as an exercise for the reader.
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
02-23-2009 12:04
Afraid I cannot get either of those to work, but thanks for your help. Perhaps I should show what I have so far: default { state_entry() { llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); } sensor(integer total_number) { llLookAt( llDetectedPos(0) + <.0, 0.0, 1.0>, 3.0, 1.0 ); } } This makes the object sense the av and turn in response to it, but it does not point right at it and I only want it to rotate around the z axis. I understand you can use llRotLookAt for this but I am unable to get that working either. I tried this as suggested: default { state_entry() { llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE); llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); } sensor(integer total_number) { llLookAt( llDetectedPos(0) + <.0, 0.0, 1.0>, 3.0, 1.0 ); } } But that made no difference. Please excuse my ignorance, I am not very experienced at this and am trying to learn. Any input appreciated 
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
02-23-2009 12:09
Well, part of your problem at least is the expression 'llDetectedPos(0)+<.0, 0.0, 1.0>'. That will make the object look just [EDIT: ABOVE] the detected avatar. You might want to make it just 'llDetectedPos(0)'. Or store the result of that in a vector variable and then set the z-component of that vector equal to that in the position of your object.
Also, I believe llLookAt() points the local z-axis toward the point mentioned. It is more common that the local x-axis represents "forward". In the Edit window, select the "Local" coordinate frame, then select your object (if it is already selected, select something else and then go back to it). Which color axis is pointing "forward"? If it is red, that's the local x-axis. If it is green, that's the local y-axis. If it is blue, that's the local z-axis. If none of those point "forward", you might need to do some careful adjusting to the rotation to get your object pointed in the right way.
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
02-23-2009 13:46
Thanks for the info on axes, that was new to me and is bound to be useful.
I have tried this too:
default { state_entry() { llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE); } sensor(integer total_number) { llRotLookAt( llDetectedRot(0) + <0.0, 0.0, 0.0, 0.0>, 3.0, 1.0 ); } }
Finally got the llRotLookAt command to work but this seems to make the object emulate the av's rotation, so that if you turn your back on it, it turns away from you. If I can stop it doing that I have it, but I am still fiddling with it at this stage.
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-23-2009 17:24
From: Layton Destiny Finally got the llRotLookAt command to work but this seems to make the object emulate the av's rotation, so that if you turn your back on it, it turns away from you. If I can stop it doing that I have it, but I am still fiddling with it at this stage. That is the correct behaviour, it will rotate to the same rotation as the detected rotation. Try llLookAt instead which will point the z axis at the target. Setting status on the axis will not stop all the axes(who in the heck knew that the plural of axis is axes????) from rotating with this function. Here I am cheating it so that it will point the z axis at the target but at the same elevation. default { state_entry() { llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); } sensor(integer total_number) { vector pos = llGetPos(); vector target = llDetectedPos(0); target.z = pos.z; llLookAt(target, 3,1); } }
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
02-23-2009 19:30
From: Jesse Barnett That is the correct behaviour, it will rotate to the same rotation as the detected rotation. Try llLookAt instead which will point the z axis at the target. Setting status on the axis will not stop all the axes(who in the heck knew that the plural of axis is axes????) from rotating with this function. Here I am cheating it so that it will point the z axis at the target but at the same elevation. default { state_entry() { llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); } sensor(integer total_number) { vector pos = llGetPos(); vector target = llDetectedPos(0); target.z = pos.z; llLookAt(target, 3,1); } }
very nice jesse, helps alot to make sure it still looks straight ahead instead of a little up or down depending on the avatar's height, i was struggling with that a couple months ago and never thought of that. i never used the script i was trying work on. i think i got the agent's height and then added 45% of that to the detected z position, so it was roughly pointing at the head but it would still have a little bit of an odd rotation sometimes edit: a while back someone was trying to get an object to stop "facing down" when it was supposed to look at the avatar. and because as explained above, llLookAt makes the z axis point towards the target, the solution was to make the root invisible or work it into the object another way and rotate it away from the rest of the links, so that when the root was pointing at the target, the rest of the object would face the target as desired
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-23-2009 19:49
Burning Life or some other celebration a couple of years ago is the only time I have done a display. About 20 clown heads with llLookAt in their noses and threw in a Swarm script. They would all just kind of meander around until some poor soul got too close and then they would all turn and stare at the same time. I never had what you would call a clown phobia but it even got to be kind of creepy to me as I tweaked the scripts 
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
|
02-23-2009 20:32
From: Jesse Barnett Burning Life or some other celebration a couple of years ago is the only time I have done a display. About 20 clown heads with llLookAt in their noses and threw in a Swarm script. They would all just kind of meander around until some poor soul got too close and then they would all turn and stare at the same time. I never had what you would call a clown phobia but it even got to be kind of creepy to me as I tweaked the scripts  lol nice
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
02-23-2009 23:52
Wrote this a while ago, works fine for me. // This is a script designed to look at the nearest avatar vector startPos; vector curPos; vector oldpos = <0,0,0>; vector offset; // offset from Agent integer iteration; float rotationRate; // degrees of rotation per iteration float sensorInterval = 1; // seconds between sensor scan.
default { state_entry() { key id; llSensorRepeat( "", id, AGENT, 96, PI, sensorInterval ); llSetStatus( 1, FALSE ); // turn Physics off. llSay (0,"ready..."); }
sensor(integer total_number) { vector position = llDetectedPos(0); llLookAt (position,1,.1); } }
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
02-24-2009 05:19
Thank you to everyone for their suggestions. Thanks to you , and help from friends in world, I now have several ways to solve this problem, and some increased understanding of of LSL. Maybe one day I will even comprehend it 
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-24-2009 12:51
of course you could creep everyone out with an eye that seems to always look at everyone's screen (black sphere inside a hollow sphere colored on the inside only, inside a hollow white sphere colored on the inside only)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-24-2009 12:56
From: Void Singer of course you could creep everyone out with an eye that seems to always look at everyone's screen (black sphere inside a hollow sphere colored on the inside only, inside a hollow white sphere colored on the inside only) Nice! And maybe make it blink????? Sounds like a nice project
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
03-04-2009 20:59
Hi again. Thanks to all who contributed to finding a solution for this. I am using this code and it works great: default { state_entry() { llSensorRepeat("", "", AGENT, 20.0, PI, 0.2); } sensor(integer total_number) { vector pos = llGetPos(); vector target = llDetectedPos(0); target.z = pos.z; llLookAt(target, 3,1); } }
However, I am now looking for a code to add to the script so that the object will rise by a set amount (say 10m for the sake of example) as it turns toward the nearest av. Any input whatsoever very much appreciated 
|
|
Layton Destiny
Crackpot Inventor
Join date: 28 Feb 2008
Posts: 13
|
03-06-2009 14:05
*Bump* 
|
|
Zoey Helgerud
Overqualified
Join date: 13 Jun 2007
Posts: 44
|
03-07-2009 10:02
setting STATUS_ROTATE_X, STATUS_ROTATE_Y and STATUS_ROTATE_Z only prevents rotation due to physical collisions.
When they are set to false on a physical object, they will only rotate about that axis if told to by a script.
All you need to do is store the vector position of an avatar, and then change the z-value to match the position of the object you're rotating. that way, it will never tilt up. Unless the detected avatar is within the same space the object is in, in which case it may be slightly twitchy, as it tries to point inside itself.
so:
vector here = ZERO_VECTOR; vector mySize = ZERO_VECTOR;
default { state_entry(){ llSensorRepeat("", NULL_KEY, AGENT, 96, 4*PI, 0.5); here = llGetPos(); mySize = llGetScale(); } on_rez(integer param){ here = llGetPos(); mySize = llGetScale(); } sensor(integer total){ vector tpos = llDetectedPos(0); // detected objects ordered by their proximity to the sensor
float distance = llVecDist(here, tpos); if (distance < mySize.x){ tpos *= (distance/mySize.x) * 1.5; // if the object is really close, look at a point behind it } tpos.z = here.z; // adjust target altitude to object's center to avoid tilting vertically llLookAt(tpos, 0.5, 1); } }
|
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
03-07-2009 10:07
From: Zoey Helgerud setting STATUS_ROTATE_X, STATUS_ROTATE_Y and STATUS_ROTATE_Z only prevents rotation due to physical collisions.
When they are set to false on a physical object, they will only rotate about that axis if told to by a script.
All you need to do is store the vector position of an avatar, and then change the z-value to match the position of the object you're rotating. that way, it will never tilt up. Unless the detected avatar is within the same space the object is in, in which case it may be slightly twitchy, as it tries to point inside itself.
so:
vector here = ZERO_VECTOR; vector mySize = ZERO_VECTOR;
default { state_entry(){ llSensorRepeat("", NULL_KEY, AGENT, 96, 4*PI, 0.5); here = llGetPos(); mySize = llGetScale(); } on_rez(integer param){ here = llGetPos(); mySize = llGetScale(); } sensor(integer total){ vector tpos = llDetectedPos(0); // detected objects ordered by their proximity to the sensor
float distance = llVecDist(here, tpos); if (distance < mySize.x){ tpos *= (distance/mySize.x) * 1.5; // if the object is really close, look at a point behind it } tpos.z = here.z; // adjust target altitude to object's center to avoid tilting vertically llLookAt(tpos, 0.5, 1); } } Look at post #8
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime. From: someone I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
|