llLookAt only works once?
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
10-12-2004 16:26
I have the following script, and the first time, it'll turn towards the named target, after that, all the debugging text happens, but the object doesn't rotate again. What am I doing wrong/missing? init() { // Listen only to the object's owner. llListen( 1, "", llGetOwner(), "" ); llStopLookAt(); }
default {
state_entry() { init(); }
touch(integer unused) { init(); } listen(integer iNotUsed, string sNotUsed, key kNotUsed, string sMessage) { llSetText ("Searching for: " + sMessage, <1,0,0>, 2.0 ); llSensor( sMessage, NULL_KEY, AGENT, 96.0, 2*3.1416); // search slightly over 360 degres } sensor(integer count) { // llSetText("Found something",<1,0,0>,2.0); if (count >1 ) { llSetText("Too many matches",<1,0,0>,2.0); } else { llSetText("Found!",<1,0,0>,2.0); vector target = llDetectedGrab(1); //llLookAt(vector target, float strength, float damping); llLookAt(target,100,.1); } llSensorRemove(); init(); } no_sensor() { llSetText("Target not found",<1,0,0>,2.0); init (); } }
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
10-12-2004 17:12
From: Spuds Milk init() { // Listen only to the object's owner. llListen( 1, "", llGetOwner(), "" ); llStopLookAt(); }
This isn't your problem, however it's still bad. If this is the very top of your code it should look like... integer listen1;
init() { // Listen only to the object's owner. llListenRemove(listen1); listen1 = llListen( 1, "", llGetOwner(), "" ); llStopLookAt(); }
It needs to be this way because in your on touch event you call init, which adds a listen (listens do not replace previous listens). Eventually if you touched this code enough it would fill up your listen quota and your script would stop completely. See where you used llDetectedGrab(1) in your sensor event? Not sure what you think detected grab does, but it doesn't give you the position of what was sensed. Replace that with llDetectedPos(0). You also used 1, instead of 0. If you want the first/only thing detected it should be 0. also  ... you have llSensorRemove(); at the end of your sensor event. Doesn't hurt anything but doesn't need to be there since you aren't using llSensorRepeat. llSensor only goes once and then removes itself. You also call init(); on touch, sensor, and no_sensor. Why? you don't need to redo the listen again. The only thing I can think of is your calling it to use llStopLookAt()? No reason to do that. Just use llSleep(0.1); and then llStopLookAt(); in your sensor event after you call llLookAt(...);
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
10-12-2004 17:20
cleaned the multiple listens up as suggested, so cleaner., though that doesn't fix the core problem of llLookAt only rotateing the object once.
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
10-12-2004 17:24
hehe, sorry, I keep editing it  , didn't expect you to look at it so quickly. It's added a bit more now. Also, you use 2*3.1416. There's a TWO_PI constants which is shorter to type and more precise. there's also a PI constant.
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
10-12-2004 17:26
oh ya, and I think instead of a touch event you might want touch_start. touch supposedly continues triggering until they let up the mouse button. touch_start just triggers once when they press the mouse button.
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
10-14-2004 14:48
touch only seems to run once, when I had llSay's in it. Just wish I knew why the llLookAt doesn't work twice
|
Rickard Roentgen
Renaissance Punk
Join date: 4 Apr 2004
Posts: 1,869
|
10-14-2004 15:57
did you replace...
vector target = llDetectedGrab(1);
with...
vector target = llDetectedPos(0);
?
|
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
|
10-14-2004 16:33
Does this version work? I'm currently at work and can't test it.  integer listen1;
init() { // Listen only to the object's owner. llListenRemove(listen1); listen1 = llListen( 1, "", llGetOwner(), "" ); llStopLookAt(); }
default {
state_entry() { init(); }
touch_start(integer unused) { init(); } listen(integer iNotUsed, string sNotUsed, key kNotUsed, string sMessage) { llStopLookAt() ; // ** Added this! ** llSetText ("Searching for: " + sMessage, <1,0,0>, 2.0 ); llSensor( sMessage, NULL_KEY, AGENT, 96.0, 2*3.1416); // search slightly over 360 degres } sensor(integer count) { // llSetText("Found something",<1,0,0>,2.0); if (count > 1 ) { llSetText("Too many matches",<1,0,0>,2.0); } else { llSetText("Found!",<1,0,0>,2.0); // vector target = llDetectedGrab(1); vector target = llDetectedPos( 0 ) ; // ** Added this ** //llLookAt(vector target, float strength, float damping); llLookAt(target,100,.1); } llSensorRemove(); init(); } no_sensor() { llSetText("Target not found",<1,0,0>,2.0); init (); } }
_____________________
- Making everyone's day just a little more surreal -
Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
|
Spuds Milk
Registered User
Join date: 28 Sep 2004
Posts: 94
|
10-17-2004 12:50
Took Cross'es code and it worked perfectly, commented out the added llStopLookat, and it still works, so, as Richard said it was the llDetectedPos, instead of llDetectedGrab. Now to go back and strip out all the debugging/tests  THANKYOU!!!!!!!!!!!!!!!!!!!!!!!!!1
|
Timeless Prototype
Humble
Join date: 14 Aug 2004
Posts: 216
|
10-19-2004 03:09
I haven't even looked in depth at your code, but always do a llStopLookAt() directly before the next llLookAt(). Same goes for any llMoveToTarget()'s, they should be preceded immediatel with a llStopMoveToTarget().
- Timeless
|