Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help Please...Need a sliding script

Mychelle Foley
Registered User
Join date: 31 Mar 2006
Posts: 11
09-05-2006 23:11
hey there i am just starting to understand compleated scripts and having a heck of a time writing them from scrach. i really need 2 scripts....
i need a prim to move smoothlyabout .5 meters vertically down from the start point.
also i am trying to do a touch rotate script that starts at 0 goes to 90 stops and turns back to 270 degrees each with a touch .....is it even possable?? im starting to pull my hair out here..im hoping it is not a futile effort.
Thanks
HtF Visconti
Registered User
Join date: 21 Jul 2006
Posts: 123
09-06-2006 02:01
Hi,

for the first one (you said prim - not object):

llGetPostion() gives you the current position. To move up you need the z-component of the vector and add your desired offset like this:

vector startpos;
vector newpos;
integer offset;

startpos = llGetPos();
newpos = <startpos.x, startpos.y, startpos.z + offset);

Since I cannot access SL now I cannot give you a real script for it. But the above code segment should help you on your way.

Second:

I need a bit more info - which axis to rotate around?

Let us assume we're talking prims and not objects again and you'd want to rotate around the z axis with each touch by 90 *more* degrees.

So - first we need the quaternion for a 90° rotation - no SL access so pure guesswork here ...

rotation currentrot;
rotation z_by_90;
rotation newrot;

z_by_90 = llEuler2Rot(<0,0,90> * DEG_TO_RAD);
currentrot = llGetRot();

in order to rotate *in addition* to your current rotation you have to divide or multiply the desired rotation by the rotation you currently have - English is a foreign language for me - I hope I put this right. Division or multiplication defines the direction (positive or negative) of the rotation.

newrot = z_by_90 / currentrot or newrot = z_by_90 * currentrot

Then you set the new new rotation

llSetRot(newrot)

done!

If you loop this by touches, llGetRot() will return the already rotated position so you will get your additional 90° for free by just using the code unaltered in the loop. After 4 rotations you're back where you started ....

No guarantee for this working as written without tests in SL but I have a good feeling :)
Mychelle Foley
Registered User
Join date: 31 Mar 2006
Posts: 11
wow thanks
09-06-2006 10:45
i don't know if they work yet but ill definatlly let all know if they do.
i am using prim because it is the base i want to move.. for the second script yes it is the z axis and for the first it is also the z i need it to move by....
if you can bugg me in world it would rock maybe you can explain it to me better..... im trying to learn and it is much slower to understand than i would like
Mychelle Foley
Mychelle Foley
Registered User
Join date: 31 Mar 2006
Posts: 11
HELP please!!!
09-06-2006 22:26
hey there i tried to write the script into world and i think im sadly lacking in the skills needed to do so suscessfully.......... any one please help!!!!!!
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
09-08-2006 09:58
This simplified moving target script does the basic movement

CODE

// Moving target script based on Sliding door movement script by
// JohnG Linden and edited by Cutter Rubio to make it work with later releases of LSL
//
// where we are when we started
vector gStartPos;
rotation gStartRot;

// displacement vector X, Y, Z so straight up down is <0,0,1.0>
vector gDelta = <1.5, 1.0, 1.0>;
// how long it takes to move
float gTimer = 1.6;
float gTime = 1.6;
// how many steps along the way
float gTimeStep = 0.2;

//
// states begin here
//

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

state_entry()
{
// no physics until needed
llSetStatus(STATUS_PHYSICS, FALSE);
// but set proper values here anyway
llSetBuoyancy(1.0);
// save position
gStartPos = llGetPos();
gStartRot = llGetRot();
gTimer = 0.0;
}

touch(integer num)
{
llSetPos(gStartPos);
llSetRot(gStartRot);
state move_right;
}
}

state move_right
{
on_rez(integer arg) { llResetScript(); }

state_entry()
{
// turn on physics
// never allow it to rotate
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
// start the process
llResetTime();
gTimer = 0.0;
llSetTimerEvent(gTimeStep);
}

touch(integer num)
{
llSetPos(gStartPos);
llSetRot(gStartRot);
state default;
}


timer()
{
float time = llGetTime();

if ( time > gTime + gTimeStep)
{
// stop timer interrupts
llSetTimerEvent(0.0);
// back the other way
state move_left;
} else
{
// interpolate proper position
vector pos = gDelta * (time / gTime);
// orient properly
pos *= gStartRot;
// move there
llMoveToTarget(gStartPos + pos, gTimeStep * 1.5);

}
}
}

state move_left
{
on_rez(integer arg) { llResetScript(); }

state_entry()
{
// turn on physics
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
// start process
llResetTime();
gTimer = 0.0;
llSetTimerEvent(gTimeStep);
}

touch(integer num)
{
state default;
}

timer()
{
float time = llGetTime();

if ( time > gTime + gTimeStep)
{
// stop timer interrupts
llSetTimerEvent(0.0);
// reachd the limit
state move_right;
}
else
{
// interpolate proper position
vector pos = gDelta * (1.0 - (time / gTime));
// orient properly
pos *= gStartRot;
// move there
llMoveToTarget(gStartPos + pos, gTimeStep * 1.5);

}
}

}