Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Smooth Garage Door Script
- //
- // By Kelp
- //
- // Uses llSetKeyFramedMotion to make the animation as smooth as possible
- // Multiple states are used to allow or disallow touching at the appropriate times
- list KFMData = []; //Global Likst to allow oersistence across states
- float fTravelTime = 5.0; //Length of time it takes to move up and down.
- //Safety net variables. You should only move or rez the object in the down position.
- vector vSafePos;
- rotation rSafeRot;
- default
- {
- state_entry()
- {
- //Must set physics shape to convex to allow keyframed animations to work
- llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
- state WaitToGoUp;
- }
- }
- //Wait to be touched before going up
- state WaitToGoUp
- {
- //Must use touch_end in order to change states. Using touch or touch_start will cause problems
- touch_end(integer detected)
- {
- state Raising;
- }
- }
- //Wait to be touched before gping down
- state WaitToGoDown
- {
- state_entry()
- {
- llSetTimerEvent(10.0);
- }
- touch_end(integer detected)
- {
- llSetTimerEvent(0.0);
- state Lowering;
- }
- timer()
- {
- llSetTimerEvent(0.0);
- state Lowering;
- }
- }
- //Move the object up and back and rotate it 90 degrees all at once
- state Raising
- {
- state_entry()
- {
- //Save the position and rotation before moving.
- vSafePos = llGetPos();
- rSafeRot = llGetRot();
- //Need the height of the object
- vector Size = llGetScale();
- //Build the list for llSetKeyframedMotion
- //Moving up half the distance of the height, and back the same amount
- //Also adjust for the rotation of the object
- //And rotate it -90 degrees
- //Take fTravelTime seconds to complete the move
- KFMData = [<0, Size.z / 2, Size.z / 2> * llGetRot(), llEuler2Rot(<-90, 0, 0> * DEG_TO_RAD), fTravelTime];
- //Move forward, which in this case is up and to the back
- llSetKeyframedMotion(KFMData, [KFM_MODE, KFM_FORWARD]);
- }
- moving_end()
- {
- //When the prim stops moving, cwait to be touched
- state WaitToGoDown;
- }
- }
- state Lowering
- {
- state_entry()
- {
- //Use the same list generated in Raising, but go in reverse (forward, and down)
- llSetKeyframedMotion(KFMData, [KFM_MODE, KFM_REVERSE]);
- }
- moving_end()
- {
- //Restore the object to its original postion and rotation/
- //This is where the object should be after the keframes, however
- //occasionally things go wrong,, due to lag, or user intervention
- //This is merely a safeguard to get back where the object started
- llSetPos(vSafePos);
- llSetRot(rSafeRot);
- //When the prim stops moving, cwait to be touched
- state WaitToGoUp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement