Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rotation for a moving animal

Granster Vultee
Registered User
Join date: 21 Jan 2008
Posts: 44
04-26-2008 09:46
I have an animated prim of a frog walking and i want it to walk in a large circle while also turning along with the circle so it always faces the same direction (ok i'm editing this to say forward). I found a script for orbiting a prim so i have it going in a circle but need now to have the prim change orientation as it move to face the same direction.

This is what I have so far:
vector rotationCenter; // point to rotate around.

default
{
state_entry()
{
llSay( 0, "Hello, Avatar!";);

llSetTextureAnim (ANIM_ON | LOOP, ALL_SIDES, 4, 4, 0, 0, 4.0);

vector startPoint = llGetPos();
rotationCenter = startPoint + < 3, 3, 3 >;
// distance to the point of rotation should probably be a
// function of the max dimension of the object.
}

touch_start(integer total_number)
{
llSay( 0, "Touched." );

// Define a "rotation" of 10 degrees around the z-axis.
rotation Z_15 = llEuler2Rot( < 0, 0, 1.5 * DEG_TO_RAD > );

integer i;
for( i = 1; i < 100; i++ ) // limit simulation time in case of
{ // unexpected behavior.
vector currentPosition = llGetPos();

vector currentOffset = currentPosition - rotationCenter;

// rotate the offset vector in the X-Y plane around the
// distant point of rotation.
vector rotatedOffset = currentOffset * Z_15;
vector newPosition = rotationCenter + rotatedOffset;

llSetPos( newPosition );
}
llSay( 0, "Orbiting stopped" );
}
}

It's probably not too hard to do for a scripter but I am new to scripting and could use some help.
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
04-26-2008 09:55
What you are asking sounds kinda weird to me..

You have a frog walking in a circle, but he doesn't face tangent to the circle he is walking, as one would normally expect. Instead you always want him facing some specific direction, like due North, while walking in a circle? That means he will be walking forward, backward, left, and right at different points along the circle.

Basically, if that is what you want, you don't want to rotate the frog at all, but just move him along the circle.

However, I have a feeling that this isn't what you are asking, but before I delve into any specific implementation suggestion, I just want you to clarify that is what you want. :)
Granster Vultee
Registered User
Join date: 21 Jan 2008
Posts: 44
04-26-2008 10:25
The problem is he always faces the same direction. Always faces north for example when i want him to turn as he is orbiting so he always faces forward. I thought that was what I was saying but if it wasn't clear I hope it is now.
Talarus Luan
Ancient Archaean Dragon
Join date: 18 Mar 2006
Posts: 4,831
04-26-2008 11:50
Yeah, I figured that was what you meant, but better to ask to make sure rather than spend time working on a solution to the wrong problem. ;)

My suggestion that is the easiest to do is to make a large ring (rez a cylinder; set the hollow to 95%, X/Y size to the diameter of your movement circle, set the Z size to 0.01) and link the frog to it somewhere on the circumference, facing tangent to the ring. Make the ring the root prim, and put a transparent texture on it. Then put the following script in the root prim:

CODE

float gfSpinRate = 0.1; // in Revolutions per Second, in this case 1 revolution every 10 seconds

default {
state_entry() {
llTargetOmega(<0.0,0.0,1.0>,gfSpinRate*TWO_PI,1.0);
}
}


Change the spinrate variable to adjust for the best speed to match the frog's animation.

If the circle is wider than 10m diameter, but less than ~35m, no biggie, just use long, thin "spokes" attached at the edge of the ring, end to end, until you get the desired radius. Note that, at some point, you may have "link distance" issues.

If you want a "really big" circle, then you have to go back to direct movement methods, which I can elaborate on, if you have the need.