12-05-2004 11:28
Take this script, toss it in a prim, and the prim will follow you and face towards you. Stick it in your pet cat and your pet cat will follow you and face you. Make sure the root prim of your "pet" is at a rotation of 0 along the X, Y, and Z axis, or <ZERO_ROTATION> - or your pet won't face you correctly. Pretty durn simple, but I've been itching to contribute SOMETHING that SOMEONE might be able to use since I couldn't get Artificial intelligence to work. :D



CODE
///////////////////////////////////////////////////////////////////////
// Open Basic Follower/Facing Script, by Logan Bauer. //
// You have permission to do whatever you'd like with //
// this script, as long as you promise to use it for good //
// and not evil. Stick it in your pet cat! Stick it in your //
// pet robot! Stick it where'ever you'd like, mutilate the //
// code all you'd like, strip out this header, do as you //
// will and... have fun! //
///////////////////////////////////////////////////////////////////////
// OFFSET is the position of your pet in relation to it's owner's position.
// For example, in the default setting below, "vector offset =<-1,0,1>;"
// I.E. (x,y,z), the -1 puts it 1m back behind owner, the 0 means don't have
// it stay left or right, and 1 means have it stay 1m above it's owner.
// So, if you wanted the script to make it follow directly in front of you,
// and to the left, then you would change it to "vector offset =<1,1,0>;"


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

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

default
{
state_entry()
{
startup();


}

on_rez(integer start_param)
{
startup();
}

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