Create a follower (object that follows) PART 2
In this second part, after explaining the first basic structure necessary for a follower, provides the script to insert the object you want to follow you.
The code is as follows:
//-------------------------------------- ----------------------
key id;
vector pos; / / record the current position vector
POSITION_OFFSET = \u0026lt;0.0, 2, -0.8>; / / set the offset (see Part 1)
key gOwner;
rotation gFwdRot;
/ / create a rotation function that depends on our rotation
GetRotation rotation (rotation rot) {
vector Fwd; ;
Fwd = llRot2Fwd (rot);
float Angle = llAtan2 ( Fwd.y, Fwd.x );
return gFwdRot * llAxisAngle2Rot (<0, 0, 1>, Angle);
}
default
{
on_rez (integer start_param)
{
llResetScript ();}
state_entry () {
id = llGetOwner ( )
llSetStatus ( STATUS_PHYSICS, TRUE); / / becomes physical ....
llSetStatus ( STATUS_PHANTOM, TRUE); / / becomes a ghost
llSensorRepeat ("", id, AGENT, 96.0, PI, 1.0); / / turn on the sensor
llListen (0, "", id ,""); / / turn on the listener
}
listen (integer channel, string name, key id , string message) {
if (message == "stop") / / if scrivamo "stop" all spegnamo
{
; llSay (0, "Ok, I stop");
llSetStatus ( STATUS_PHYSICS, FALSE ) ;
llSensorRemove ();}
; else if (message == "start") / / if scrivamo "start" light sensor
{
; llSay (0, "Ok, ti seguo");
llSetStatus ( STATUS_PHYSICS, TRUE );
llSensorRepeat ("", id, AGENT, 96.0, PI, 1.0);
}
}
sensor (integer TOTAL_NUMBER) / / if the sensor detects the owner ...
{
rotation TargetRot;
rotation Rot = llDetectedRot (0); / / notes our rotation
vector pos = llDetectedPos (0);
vector Offset = POSITION_OFFSET * Rot; / / the offset varies according to the rotation
; ; / / the avatar
pos + = offset; / / position offset high
llMoveToTarget (pos, 0.4); / / moves the object to the current position with a time of 0.4
TargetRot GetRotation = (Rot )
llRotLookAt (TargetRot, 0.5, 2); / / The first addresses his "face" as it is rotated in relation to our avatar
}
no_sensor () / / otherwise {
llSleep (5); / / wait 5 seconds .... ...
llDie (); / / Object "dies"
}}
//------------------- --------------------------------------------------
that remains is to prove it!
0 comments:
Post a Comment