Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. // Smooth Garage Door Script
  2. //
  3. // By Kelp
  4. //
  5. // Uses llSetKeyFramedMotion to make the animation as smooth as possible
  6. // Multiple states are used to allow or disallow touching at the appropriate times
  7.  
  8. list KFMData = []; //Global Likst to allow oersistence across states
  9. float fTravelTime = 5.0; //Length of time it takes to move up and down.
  10.  
  11. //Safety net variables. You should only move or rez the object in the down position.
  12. vector vSafePos;
  13. rotation rSafeRot;
  14.  
  15. default
  16. {
  17. state_entry()
  18. {
  19. //Must set physics shape to convex to allow keyframed animations to work
  20. llSetPrimitiveParams([PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]);
  21.  
  22. state WaitToGoUp;
  23. }
  24. }
  25.  
  26. //Wait to be touched before going up
  27. state WaitToGoUp
  28. {
  29. //Must use touch_end in order to change states. Using touch or touch_start will cause problems
  30. touch_end(integer detected)
  31. {
  32. state Raising;
  33. }
  34.  
  35. }
  36.  
  37. //Wait to be touched before gping down
  38. state WaitToGoDown
  39. {
  40. state_entry()
  41. {
  42. llSetTimerEvent(10.0);
  43. }
  44.  
  45. touch_end(integer detected)
  46. {
  47. llSetTimerEvent(0.0);
  48. state Lowering;
  49. }
  50.  
  51. timer()
  52. {
  53. llSetTimerEvent(0.0);
  54. state Lowering;
  55. }
  56. }
  57.  
  58. //Move the object up and back and rotate it 90 degrees all at once
  59. state Raising
  60. {
  61. state_entry()
  62. {
  63. //Save the position and rotation before moving.
  64. vSafePos = llGetPos();
  65. rSafeRot = llGetRot();
  66.  
  67. //Need the height of the object
  68. vector Size = llGetScale();
  69.  
  70. //Build the list for llSetKeyframedMotion
  71. //Moving up half the distance of the height, and back the same amount
  72. //Also adjust for the rotation of the object
  73. //And rotate it -90 degrees
  74. //Take fTravelTime seconds to complete the move
  75. KFMData = [<0, Size.z / 2, Size.z / 2> * llGetRot(), llEuler2Rot(<-90, 0, 0> * DEG_TO_RAD), fTravelTime];
  76.  
  77. //Move forward, which in this case is up and to the back
  78. llSetKeyframedMotion(KFMData, [KFM_MODE, KFM_FORWARD]);
  79. }
  80.  
  81. moving_end()
  82. {
  83. //When the prim stops moving, cwait to be touched
  84. state WaitToGoDown;
  85. }
  86. }
  87.  
  88. state Lowering
  89. {
  90. state_entry()
  91. {
  92. //Use the same list generated in Raising, but go in reverse (forward, and down)
  93. llSetKeyframedMotion(KFMData, [KFM_MODE, KFM_REVERSE]);
  94. }
  95.  
  96. moving_end()
  97. {
  98. //Restore the object to its original postion and rotation/
  99. //This is where the object should be after the keframes, however
  100. //occasionally things go wrong,, due to lag, or user intervention
  101. //This is merely a safeguard to get back where the object started
  102. llSetPos(vSafePos);
  103. llSetRot(rSafeRot);
  104.  
  105. //When the prim stops moving, cwait to be touched
  106. state WaitToGoUp;
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement