Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need Help with Follow Script

Shayna Korobase
Registered User
Join date: 8 May 2007
Posts: 454
09-25-2008 12:44
I have a script that I have been tinkering with for hours but I can't seem to get it right. It's a follow script. I'm making cute little halloween gadgets like ghosts and goblins that follo my visitors. But... they'll only follow me. How can I get it to follow anyone that comes within 20 meters? The script is below and THANK YOU in adavnace :-)




vector offset = < -1, 0, 1>; //1 meter behind and 1 meter above owner's center.

default
{
state_entry()
{
llSetStatus(STATUS_PHYSICS, TRUE);
// Little pause to allow server to make potentially large linked object physical.
llSleep(0.1);
// Look for owner within 20 metres in 360 degree arc every 1 seconds.
llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
}
sensor(integer total_number)
{ // Owner detected...
// Get position and rotation
vector pos = llDetectedPos(0);
rotation rot = llDetectedRot(0);
// Offset back one metre in X and up one metre in Z based on world coordinates.
// use whatever offset you want.
vector worldOffset = offset;
// Offset relative to owner needs a quaternion.
vector avOffset = offset * rot;

pos += avOffset; // use the one you want, world or relative to AV.

llMoveToTarget(pos,0.4);
}
}
Cappy Frantisek
Open Source is the Devil!
Join date: 27 Oct 2006
Posts: 400
Remove the llGetOwner
09-25-2008 13:00
Instead of having the sensor look for you (the owner of the prims) ie.
llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);

Use an open filter ie.
llSensorRepeat("", NULL_KEY, AGENT, 20.0, PI,1.0);

Hope that helps!

llSensorRepeat(string name, key id, integer type, float range, float arc, float rate)

Performs a repeating sensor scan for name and id with type (AGENT, ACTIVE, PASSIVE, and/or SCRIPTED) within range meters and arc radians of forward vector (name and/or id can be empty or 0). A range of 0.0m does perform a scan. The parameters have the same function as llSensor, except rate, which defines the number of seconds between repeated sensor or no_sensor calls.
Shayna Korobase
Registered User
Join date: 8 May 2007
Posts: 454
09-25-2008 13:35
Thank you sooooo much!
Cheewha Palen
Registered User
Join date: 27 Nov 2007
Posts: 78
09-26-2008 02:40
Is there a way to make something like this that follows you look a bit more natural? To explain, this type of follow is locked in adistance and position away from the avatar it follows. If it is directly behind you then as you turn it will keep pace and turn with you keeping as close to the stated distance and position as possible. This makes it look like a sort of attachment.

Is there a way instead to make it follow but in a more non linear way? like say once you have moved 3 or 4 meters in a given direction it will "catch up" to you within those parameters and as long as you are within those 3 or 4 feet it does nothing until you are out of range again?


I am guessing this would work as a timed event that does a sensor sweep to see if you are still in range and then move to target(?) would be invoked if it realized you are not. it could face you at all times so whether you are walking away or looking at it it would be focused on you.

Any thoughts on this?
Dan Colville
Registered User
Join date: 28 Jul 2006
Posts: 26
09-26-2008 04:17
//hay i got two scripts one that i have got working and another from a auto script website

//First from the website:
// This script was auto-generated by Ann Enigma's script autogenerator
// available at http://www.3greeneggs.com/autoscript/
-----------------------------------------------------------------------------------------
key id;
setup() {
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(llGetPos(),0.1);
id = llGetOwner();
}
list recent_avatars;

add_avatar(string name) {
if(!seen(name)) {
recent_avatars += name;
if (llGetListLength(recent_avatars) > 25) {
recent_avatars = llDeleteSubList(recent_avatars,0,0);
}
}
}
integer seen(string name) {
if(llListFindList(recent_avatars,[name]) > -1) { return TRUE; }
return FALSE;
}


default
{

state_entry() {
llSensorRepeat("", NULL_KEY, AGENT, 20, PI, 5);
}
sensor(integer total_number) {
if(!seen(llDetectedName(0))) {

add_avatar(llDetectedName(0));
}
}

}
----------------------------------------------
//This is one i have been messing with: This one here will just follow you and to me it looks //good

vector offset =<-1,2,1>;

startup()
{
vector pos = llGetPos();
llSetStatus(STATUS_ROTATE_Z,TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
key id = llGetOwner();
llSensorRemove();
llSensorRepeat("",llGetOwner(),AGENT,10,2*PI,.1);
}

default
{
state_entry()
{
startup();


}

on_rez(integer start_param)
{
startup();
}

sensor(integer total_number)
{
vector pos = llDetectedPos(0);
llMoveToTarget(pos+offset*llDetectedRot(360),.3);
llLookAt(pos, .1 , 1);
}
}

Test this i have made the mistake before where i have not copied over the full script if they do tell me