Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Rocking Script

Belle Bartlett
Registered User
Join date: 26 Dec 2006
Posts: 17
03-26-2008 22:12
I have a script that I am trying to use in some furniture. It has a nice smooth glide to it but has a few problems.

I need a script that will turn direction relative to the root prim and not drift.

Actually I would like this script to do that ...the smooth glide is exactly what I want just need help figuring out how to correct the other problems ....the drifting and turning direction relative to the root prim.


Here is the contents of the script .....


float iDir = .01;
integer iSwing = 0;

default
{
state_entry()
{
llSetTimerEvent(3);
}
touch(integer total_number)
{
if (iSwing == 0)
{
iSwing = 1;
}
else
{
iSwing = 0 ;
}
}
timer()
{
if (iSwing==1)
{
if (iDir == .01)
{
iDir = -.01;
}
else
{
iDir = .01 ;
}
llTargetOmega(<0,iDir,0>,PI,2.0);
}
else
{
llTargetOmega(<0,0,0>,PI,2.0);
}



}
}



Any suggestions or ideas on how to get the effect I need with this?

Thanks in advance
Belle Bartlett
Registered User
Join date: 26 Dec 2006
Posts: 17
Update and change of script
03-27-2008 22:30
Actually this is the script that I would like help modifying......


//change distance to a smaller number. And, if the swing is too fast or slow, change timetotake.
//Created by Sandeo Goodman. Free to use as long as credit remains :-)
float distance = .3;
float timetotake = 3;
float speed;
rotation backrot;
rotation forerot;
rotation stoprot;

startSwing()
{
vector vDir;

speed = distance / timetotake;
// llOwnerSay("Speed = " + (string)speed + " at start";);
llSetTimerEvent(timetotake);
vDir = llRot2Up(llGetRot());
llSetRot(stoprot);
llTargetOmega( vDir, -distance / ( 2 * timetotake ), 1.0 );
}

swingchange()
{
vector vDir = llRot2Up(llGetRot());

// llOwnerSay("timer(): gain=" + (string)gain);
// llTargetOmega( <0,0,0>, speed, 1.0 );
if( speed < 0 ) {
llSetRot(backrot);
} else {
llSetRot(forerot);
}
llTargetOmega( vDir, speed, 1.0 );
speed = 0 - speed;
}

integer swinging = 0;

default
{
on_rez(integer sp)
{
llResetScript();
}

state_entry()
{
rotation rrot = llGetRot();
vector vrot = llRot2Euler( rrot );
stoprot = rrot;
vrot.z += distance/2;
backrot = llEuler2Rot( vrot );
vrot.z -= distance;
forerot = llEuler2Rot( vrot );

// vector vrot = llRot2Euler( llGetRot() );
// vrot.z = (distance/2);//2 * speed;
// backrot = llEuler2Rot( vrot );
// vrot.z = -(distance/2);//-2 * speed;
// forerot = llEuler2Rot( vrot );
llTargetOmega(<0,0,0>, 0, 0.0);
swinging = 0;
// vrot.z = 0;
// stoprot = llEuler2Rot( vrot );
// llSetRot( stoprot );
// llOwnerSay("Backrot: " + (string)backrot + ", forerot: " + (string)forerot);
}

timer()
{
swingchange();
}

touch_start(integer total_number)
{
if( swinging > 0 ) {
swinging = 0;
llSetTimerEvent(0.0);
llTargetOmega(<0,0,0>, 0, 0.0 );
llSetRot(stoprot);
llTargetOmega(<0,0,0>, 0, 0.0 );
} else {
swinging = 1;
startSwing();
}
}

moving_end()
{
llSleep(2.0);
llResetScript();
}
}



What I need is this script modified so that someone can rotate the root prim and have it work correctly WITHOUT resetting the script

Any help would be greatly appreciated
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
03-28-2008 16:33
Normally to get an object to use llTargetOmega relative to local axis and therefor work the same regardless of orientation is to use

llTargetOmega(<0,0,1> * llGetRot(), 1.0, 1.0);

Having said that I am far to tired to go through all your rotations to work out if that works in your script...sorry.

In terms of drift I would have the object check it's position after every time it is moved by an avatar and then periodically reset to the detected position. This apparently is due to computational errors with server side rotations over time as opposed to client side ones like TargetOmega.
_____________________
Tread softly upon the Earth for you walk on my face.