Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Pendulum script

Jaynius Shaftoe
Automated User
Join date: 9 Jan 2005
Posts: 29
04-04-2005 21:39
I am trying to code a pendulum movement, and while I have a begining of a solution, it is far from perfect. How can I dampen the movement? I tried llRotLookAt but changes to strength and damping don't seem to affect the motion speed. It also doesn't behave like llSetRot with linked objects.


This code "kinda" works, but it's not very pleasing to the eye. I need something that would move more naturaly.

CODE
default
{
state_entry()
{
while (TRUE)
{
rotation idle = llEuler2Rot(<PI, 0, 0>);
rotation amplitude = llEuler2Rot(<PI / 15, 0, 0>);

llSetRot(idle / amplitude);
llSleep(1);

llSetRot(amplitude / idle);
llSleep(1);
}
}
}
Lightwave Valkyrie
Registered User
Join date: 30 Jan 2004
Posts: 666
04-04-2005 22:24
im not sure what you are using this for but heres
two ideas: i made a large pendulum with a
joint a long pole and a large weight its very
realistic add a impulse or pushobject at the swing point
and it always will run. the other idea is to use
a filmstrip texture animation flat yea but if
this is inside a clock(?) it will look good :)
-LW
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
04-05-2005 01:47
My suggestion would be to try an llRotLookAt loop.

CODE
rotation start = <0,0,0,1>; // Sample
rotation end = <0.00000, 0.70711, 0.00000, 0.70711>; // Sample
vector incr;
integer num_steps = 10; // Number of steps
integer step = 0; // Current step
integer forward = TRUE; // Direction

default
{
state_entry()
{
llMoveToTarget(llGetPos(),0.3);
llSetStatus(STATUS_PHYSICS | STATUS_PHANTOM,TRUE);
incr = llRot2Euler(end) / num_steps;
// Set the increments
llSetTimerEvent(0.2);
}

timer()
{
if(forward && step >= num_steps)
forward = FALSE;
else if(!forward && step <= 0)
forward = TRUE;

llRotLookAt(llEuler2Rot(incr * step) * start,0.3,0.3);
if(forward)
step++;
else
step--;
}
}

Make sure you change the rotations start and end to what you want to use. That should work - if it doesn't, I screwed up my rotation math because I'm a bit tired presently.
_____________________
---