Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Follow Script

Zaine Swords
Registered User
Join date: 26 Nov 2008
Posts: 47
12-21-2008 11:34
hey, im trying to get this follow script to work right. i got it to follow me when i touch it but when i touch it again it just keeps following me. how do i fix that and how do i get it to go back to where it was rezed at?
CODE

default
{
touch_start(integer num)
{
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);
key id = llGetOwner();
llSensorRepeat("",id,AGENT,20,2*PI,.4);
}

sensor(integer total_number)
{
vector pos = llDetectedPos(0);
vector offset =<-1,0,0>;
pos+=offset;
llMoveToTarget(pos,.3);
}
}
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
12-21-2008 23:12
Hmmm... And excuse me but I can't resist to the urge to remove that sensor... ;-)

vector RezPos;
key Owner;
integer Following;
integer Handle;

default
{
on_rez(integer param) { llResetScript(); }

state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
Owner = llGetOwner();
Following = FALSE;
}

touch_start(integer num)
{
if (llDetectedKey(0) != Owner) { return; }
//
if (! Following)
{
RezPos = llGetPos();
Following = TRUE;
llSetStatus(STATUS_PHYSICS, TRUE);
llSetTimerEvent(0.4);
}
else
{
Following = FALSE;
}
}

timer()
{
if (Following)
{
vector pos = llList2Vector(llGetObjectDetails(Owner, [OBJEC_POS]), 0) + <-1.0, 0.0, 0.0>;
llMoveToTarget(pos, 0.3);
}
else
{
llSetTimerEvent(0.0);
Handle = llTarget(RezPos, 0.1);
llMoveToTarget(RezPos, 0.3);
}
}

at_target(integer num, vector target, vector pos)
{
if (! Following)
{
llSetStatus(STATUS_PHYSICS, FALSE);
llTargetRemove(Handle);
}
}
}

Untested but I'm confident... :P
Zaine Swords
Registered User
Join date: 26 Nov 2008
Posts: 47
12-22-2008 00:44
you forgot a T in line 38.. error came up saying name not in scope or something like that.. but put that T there and it works great.. thanks.. great work....
but how would you make it to where a person from a group use it?
i thought changing Owner to Group but that didnt work.. would i have to put Avatar?
Cerulean Deadlight
Registered User
Join date: 6 May 2007
Posts: 28
12-22-2008 02:03
Maybe this would work? I can't go in SL now to check. That missing T may or may not still be not there?!

vector RezPos;
integer Following;
integer Handle;
key TargetKey

default
{
on_rez(integer param) { llResetScript(); }

state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
Following = FALSE;
}

touch_start(integer num)
{
if (llDetectedGroup(0) != TRUE) { return; }
//
if (! Following)
{
TargetKey = llDetectedKey(0);
RezPos = llGetPos();
Following = TRUE;
llSetStatus(STATUS_PHYSICS, TRUE);
llSetTimerEvent(0.4);
}
else
{
Following = FALSE;
}
}

timer()
{
if (Following)
{
vector pos = llList2Vector(llGetObjectDetails(TargetKey, [OBJEC_POS]), 0) + <-1.0, 0.0, 0.0>;
llMoveToTarget(pos, 0.3);
}
else
{
llSetTimerEvent(0.0);
Handle = llTarget(RezPos, 0.1);
llMoveToTarget(RezPos, 0.3);
}
}

at_target(integer num, vector target, vector pos)
{
if (! Following)
{
llSetStatus(STATUS_PHYSICS, FALSE);
llTargetRemove(Handle);
}
}
}
Zaine Swords
Registered User
Join date: 26 Nov 2008
Posts: 47
12-22-2008 02:15
you missed a ; after keyfinder and yes that T is still missing but correct those and it works great.. thanks
Zaine Swords
Registered User
Join date: 26 Nov 2008
Posts: 47
12-30-2008 23:16
ok. i have been using this script for a few weeks now and i have come to realize that the object with the script, goes back to its GENERAL location. i have to fix it everytime someone click on it. and if you have a sphere, it tends to spin and i have to adjust it everytime someone uses it. is there a way to fix that or not? and is ther also a way to have it set that if you go so many meters away or log off or tp out of that area, will it go back to its origonal loacation?
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
01-03-2009 01:32
Maybe this is something what you want?
It stores it's starting position in the state_entry() event. So simply position your follower and reset the script.

float follow_range = 10.0 determine the range inbetween the object will follow the avatar. The follower will be 'active' as long as the avatar stays in the same sim, or it is touched by the followed avatar again. If someone else touch it, it will be 'active' directly to this new avatar.

When following, it points it's X axis the direction the avatar is facing. In it's starting pos it points the direction it was on script reset.

CODE
vector RezPos;
rotation RezRot;
integer Following;
key TargetKey;
float follow_range = 10.0;

reset_pos(){
llSetTimerEvent(0.0);
llSetStatus(STATUS_PHYSICS, FALSE);
Following = FALSE;
llSetPos(RezPos);
llSetRot(RezRot);
}

default
{
on_rez(integer param) { llResetScript(); }

state_entry()
{
RezPos = llGetPos();
RezRot = llGetRot();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, TRUE);
llSetStatus(STATUS_PHYSICS, FALSE);
Following = FALSE;
}

touch_start(integer num)
{
if (llDetectedGroup(0) != TRUE) { return; }
//
if (Following && TargetKey == llDetectedKey(0) )
{
Following = FALSE;
}
else
{
TargetKey = llDetectedKey(0);
Following = TRUE;
llSetStatus(STATUS_PHYSICS, TRUE);
llRotLookAt(RezRot,0.5,0.5);
llSetTimerEvent(0.4);
}
}

timer()
{
vector pos = llList2Vector(llGetObjectDetails(TargetKey, [OBJECT_POS]), 0) + <-1.0, 0.0, 1.0>;
rotation rot = llList2Rot(llGetObjectDetails(TargetKey, [OBJECT_ROT]), 0);
if (Following && llVecDist(RezPos, pos) < follow_range)
{
llRotLookAt(rot,0.5,0.5);
llMoveToTarget(pos, 0.3);
}
else
{
llRotLookAt(RezRot,0.5,0.5);
llMoveToTarget(RezPos, 0.3);
if (pos.x < 0 || pos.y < 0 || pos.x > 256 || pos.y > 256 ){
reset_pos();
}
else if (!Following && llVecDist(llGetPos(), RezPos ) < 0.5){
reset_pos();
}
}
}
}
Zaine Swords
Registered User
Join date: 26 Nov 2008
Posts: 47
01-03-2009 09:18
perfect.. now all i need to figure out on it is how to rotatae the object a little on follow.. but thats a minor fault. cant really blame the script for that i dont think.. but that is exactly what i'v been lookoing for.. ty
arton Rotaru
Registered User
Join date: 27 Aug 2007
Posts: 43
01-03-2009 19:22
Spins slowly and follows the right shoulder of the avatar.

vector RezPos;
rotation RezRot;
integer Following;
key TargetKey;
float follow_range = 10.0;

reset_pos(){
llSetTimerEvent(0.0);
llSetStatus(STATUS_PHYSICS|STATUS_PHANTOM, FALSE);
Following = FALSE;
llSetPos(RezPos);
llSetRot(RezRot);
llTargetOmega(<0.0,0.0,0.0>,0.0,0.0);
}

default
{
on_rez(integer param) { llResetScript(); }

state_entry()
{
RezPos = llGetPos();
RezRot = llGetRot();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, TRUE);
reset_pos();
}

touch_start(integer num)
{
if (llDetectedGroup(0) != TRUE) { return; }
//
if (Following && TargetKey == llDetectedKey(0) )
{
Following = FALSE;
}
else
{
TargetKey = llDetectedKey(0);
Following = TRUE;
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetTimerEvent(0.4);

}
}

timer()
{
rotation rot = llList2Rot(llGetObjectDetails(TargetKey, [OBJECT_ROT]), 0);
vector pos = llList2Vector(llGetObjectDetails(TargetKey, [OBJECT_POS]), 0) + <-0.4, -0.4, 1.0>*rot;
if (Following && llVecDist(RezPos, pos) < follow_range)
{
llStopLookAt();
llTargetOmega(<0.0,0.0,1.0>,PI,0.5);
llMoveToTarget(pos, 0.3);
llSetStatus(STATUS_PHYSICS|STATUS_PHANTOM, TRUE);
}
else
{
llTargetOmega(<0.0,0.0,0.0>,0.0,0.0);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, TRUE);
llRotLookAt(RezRot,0.5,0.5);
llMoveToTarget(RezPos, 0.3);
if (pos.x < 0 || pos.y < 0 || pos.x > 256 || pos.y > 256 ){
reset_pos();
}
else if (!Following && llVecDist(llGetPos(), RezPos ) < 0.5){
reset_pos();
}
}
}
}
Justy Madfess
Registered User
Join date: 1 Mar 2009
Posts: 2
03-06-2009 10:43
This is almost just what I'm looking for to get my follower to work just right, but does anybody know how to get the bloody thing to turn in my direction so it doesn't move sideways or backwards when I change direction?
Justy Madfess
Registered User
Join date: 1 Mar 2009
Posts: 2
03-06-2009 11:28
Never you mind.
I'm blind, and just saw the answer above my first post.
/me sits on the floor wearing nothing but a diaper and a dunce cap and is swinging a cat by it's tail over my head "I'm the biggest idiot ever"
:P