Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scripting Questions from a Script Noob

Tod69 Talamasca
The Human Tripod ;)
Join date: 20 Sep 2005
Posts: 4,107
02-20-2006 23:30
2 questions:

#1- Is it possible to have a script activate at the end of an animation, causing a texture or particle system to activate?

#2- Been trying to make Statues that rotate in place, like watching you, as someone walks past. I am SO stuck on where to start!!
_____________________
really pissy & mean right now and NOT happy with Life.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
02-21-2006 00:44
1) Yes, but not nicely. You'd have to time the anim, start it playing and then use a timer or sleep to fire the next thing off at that the right time.

2) Visit the wiki at http://secondlife.com/badgeo/wakka.php?wakka=HomePage. You're certainly looking for llSensor and sensor events, and at movement and dynamics. You can probably fake it with non-physical movement, in which case llSetRot() is the way to go.
Candide LeMay
Registered User
Join date: 30 Dec 2004
Posts: 538
02-21-2006 00:47
#2 - use a sensor repeat (preferably only activated when someone's around, using e.g. volume detect), llDetectedPos() in sensor event to get the position of the avatar and then llRotBetween() to figure out the rotation between your statue and the avatar. Which you then use in llSetRot(). Alternatively you can try to use llLookAt() which avoids the rotations but uses the Z axis as "forward".
_____________________
"If Mel Gibson and other cyberspace writers are right, one day the entire internet will be like Second Life." -- geldonyetich
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
02-21-2006 01:10
The wiki has good sample code for using llRotLookAt to point other axes in the direction of something else.

For statues, you will also need to make sure that they don't rotate vertically. If you're using *LookAt, you can do this quite easily by making the z position of what you're looking at equal to the z position of the statue.
Ben Bacon
Registered User
Join date: 14 Jul 2005
Posts: 809
02-21-2006 02:54
Tod69, some code from another thread to get you started. Both snippets are written for sensor events.

If you want the whole statue to rotate on the spot, this will turn it so that its positive x-axis points toward the target, keeping y horizontal and z vertical.
CODE
        vector Offset = llDetectedPos(0) - llGetPos();
float HalfAngle = llAtan2(Offset.y, Offset.x) / 2.0;
llSetRot(<0.0, 0.0, llSin(HalfAngle), llCos(HalfAngle)>);
If you want the statue to remain still, but have the head move, this one will turn the head side-to-side, and let it look up-and-down, but without cocking it to one side or the other. You will need to add limits to stop it from exceeding a natural range of motion (i.e. to stop it breaking its neck :))
CODE
        vector Offset = llDetectedPos(0) - llGetPos();

float Yaw = llAtan2(Offset.y, Offset.x) / 2.0;
float Pitch = -llAtan2(Offset.z, llSqrt(Offset.x*Offset.x + Offset.y*Offset.y)) / 2.0;

float SinYaw = llSin(Yaw);
float CosYaw = llCos(Yaw);
float SinPitch = llSin(Pitch);
float CosPitch = llCos(Pitch);

llSetRot(<-SinPitch*SinYaw, SinPitch*CosYaw, CosPitch*SinYaw, CosPitch*CosYaw>);
Tod69 Talamasca
The Human Tripod ;)
Join date: 20 Sep 2005
Posts: 4,107
Sweet!
02-21-2006 03:45
Thanks guys & gals!! I'm now a happy camper (not in the chair sense).:)
_____________________
really pissy & mean right now and NOT happy with Life.