Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

follower leash script works and works not...

Lulu Pink
Registered User
Join date: 30 Sep 2006
Posts: 18
10-23-2007 05:42
Hello,
I am trying to use a simple follower script that follows an avatar or doesnt let an avatar go farer away than defined from a rezzed object.

this is the script the avatar has attached... it worked then again does not work... is sl being buggy there or do i do something wrong?
(and... AGENT for avatars to follow but what type is an object?)

CODE

float distance = 1.5;
float time = 2;

default
{
state_entry()
{
llListen(4,"","","");
}

listen(integer channel, string name, key id, string message)
{
if (llToLower(message) == "leash");
{
llSensorRepeat(name, id, AGENT, 50, TWO_PI, time);
}
if (llToLower(message) == "unleash")
{
llSensorRemove();
}
}

sensor(integer total_number)
{
vector holder = llDetectedPos(0);
if(llVecMag(llGetPos() - holder) > distance)
{
llMoveToTarget(holder + (distance * llVecNorm(llGetPos() - holder)),0.3);
llSleep(time / 4.0);
llStopMoveToTarget();
}
}

attach(key attached)
{
llResetScript();
}
}
Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
10-23-2007 06:00
http://rpgstats.com/wiki/index.php?title=LlMoveToTarget

llMoveToTarget only works for physical objects. Nowhere in the script is the object set to physical, and so if the object itself is not physical ('Edit | Object | Physical') then llMoveToTarget will have no effect.

Thats the first place I'd look but unfortunately all you've given us to go on is "it worked then again does not work", without describing the actual behaviour now that it "does not work" :)
Lulu Pink
Registered User
Join date: 30 Sep 2006
Posts: 18
10-23-2007 06:17
hhmmmm....

first thank you for the reply... well... it is like i said... it did work yesterday and doesnt work anymore today... and drives me nuts like this.

The script is for testing anyway in the only prim that is attached and will be in the root prim of the attachment as well. Dont objects get physical when attached somehow as the avi is physical? (a wild guess)

I cannot set the prim to physical as it has a listen in the script(?) and i get:

"Can't enable physics for objects that interpenetrate others"
Yumi Murakami
DoIt!AttachTheEarOfACat!
Join date: 27 Sep 2005
Posts: 6,860
10-23-2007 07:33
llSensorRepeat is SO last version. All the cool kids are using llGetObjectDetails now. :)

The above message, by the way, is wrong - llMoveToTarget *will* work on a non-physical object that is attached to an avatar, and will move the avatar.

Your method of doing the movement is more complicated that it needs to be. You're calculating the furthest point away from the leash-holder that the wearer is "allowed" to be, an moving them there, then blocking for a short time. The problem with this is that if the leash-holder has moved on in the meantime, that location probably no longer has any significance. Worse yet, if the wearer actually moves (under their own steam) CLOSER to the leash-holder than that point, the leash will push them BACK - certainly not what's intended!

The usual way of doing this is as follows:

1 - Set an llTarget at the leash-holder's location, with the range specified (you can specify a range for llTarget - it's very handy! :)
2 - Start an llMoveToTarget directly towards the leash-holder's location.
3 - If the leash-holder moves, remove the old llTarget, start a new one at their new location, and start a new llMoveToTarget to get there.
4 - If an at_target event fires, stop the llMoveToTarget and remove the llTarget.

Remember that you'll also need something to allow for the leash-holder moving out of range or teleporting, which can leave the wearer in a great pickle otherwise!
Debbie Trilling
Our Lady of Peenemünde
Join date: 17 Oct 2006
Posts: 434
10-23-2007 07:39
From: someone
"Can't enable physics for objects that interpenetrate others"


This message means that your object is interacting with objects that are not part of the linked set. It does not mean that the object is incapable of being a physical object.

Whilst in 'Edit', try lifting the object higher to ensure it is totally off the floor (or move to left or right to ensure it is totally away from walls etc) and then reset the 'Physical' attribute.

From: someone
A physical object will come to a halt (settle)--and even lose its physical status if it interpenetrates something in the process of settling


I have now an the opportunity to try this script in-world & it does indeed follow but *only if the 'Physical' attribute is set*. It does not follow if this attribute is not set.

You might want to consider using instead this version of the same script. Note that the script nows sets the object to physical using llSetStatus on 'leash', and unsets physical on 'unleash'

CODE

float distance = 1.5;
float time = 2;

default
{
state_entry()
{
llSetStatus(STATUS_PHYSICS , FALSE);
llListen(4,"","","");
}

listen(integer channel, string name, key id, string message)
{
if (llToLower(message) == "leash");
{
llSetStatus(STATUS_PHYSICS , TRUE);
llSensorRepeat(name, id, AGENT, 50, TWO_PI, time);
}
if (llToLower(message) == "unleash")
{
llSetStatus(STATUS_PHYSICS , FALSE);
llSensorRemove();
}
}

sensor(integer total_number)
{
vector holder = llDetectedPos(0);
if(llVecMag(llGetPos() - holder) > distance)
{
llMoveToTarget(holder + (distance * llVecNorm(llGetPos() - holder)),0.3);
llSleep(time / 4.0);
llStopMoveToTarget();
}
}

attach(key attached)
{
llResetScript();
}
}



EDIT: "this is the script the avatar has attached". Sorry, missed this and incorrectly assumed it was a "simple follower script that follows an avatar"
Darien Caldwell
Registered User
Join date: 12 Oct 2006
Posts: 3,127
10-23-2007 12:21
If the item is attached to an avatar, it does not have to be physical.

I suspect you are running into the long time bug where, if you recompile a script that uses llMoveToTarget while it's in an attachment, it stops working. To make it work again, remove the attachment, and rewear. It's as simple as that. :)
_____________________