Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Follower script tips

Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-30-2005 04:48
I've made a script (see below) that when in a prim makes the prim turn to face a target in the same sim and move fairly promptly to be close to it. It works. If I attach it to myself, I was expecting to move, but I stand still. Any ideas?

CODE

integer follow=TRUE; //Are you to follow?
string followTarget="poolside"; //Who you're meant to follow
integer followRange=10; //How far away you're meant to be.
default
{
state_entry()
{
llSensorRepeat(followTarget, NULL_KEY, AGENT | ACTIVE | PASSIVE, 96, PI, 0.2);
}
sensor(integer detected)
{
vector where=llDetectedPos(0);
rotation look=llDetectedRot(0);
vector here=llGetPos();
float distance=llVecDist(here, where);
if(distance > followRange)
{
vector run=where - here;
float cos=(run.x / distance);
float sin=(run.y / distance);
vector aim=<0,0, llAcos(cos)>;
if(sin < 0)
{
aim+=<0,0,PI>;
}
llSetRot(llEuler2Rot(aim));
vector target=here + <cos * 2, sin * 2, (run.z / distance * 2)>;
llSetPos(target);
}
}
no_sensor()
{
llInstantMessage(llGetOwner(), "Cannot detect follow target within range.");
}
}


This is to add a function to something else, so there are ways to turn it off etc, although not in this version.

Any help please?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
03-30-2005 05:48
Kinematics don't work on avatars - you need to use kinetic tools like llRotLookAt(), llMoveToTarget() and thier buddies.
Wiki page for reference.
_____________________
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
03-30-2005 09:53
Thank you, now to go and experiment!

And having experimented, it works, thanks for the tip!