WordsmithJarvinen

SimpleSit (LSL)

Apr 2nd, 2019
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ******************************************************************************
  2. //
  3. //  SimpleSit
  4. //
  5. //      Sets the sit target at a position given in natural sitting coordinates
  6. //      (x-axis from front to back, y-axis from left to right, z-axis upward)
  7. //
  8. //  Wordsmith Jarvinen, 02 April 2019
  9. //
  10. // ******************************************************************************
  11.  
  12. // Select a position and orientation in natural/normalized sitting coordinates
  13.  
  14. vector myPos    = <0.40, 0.0, 0.55>;
  15. vector myAngles = <0.0,  0.0, 0.0>;
  16.  
  17. // Capture the rotation that brings the prim from its default orientation to
  18. // the natural orientation for sitting with the avatar facing the +X direction
  19.  
  20. vector  angles = <0.0, 0.0, 90.0>;
  21.  
  22. default {
  23.  
  24.     state_entry () {
  25.  
  26.  
  27.         // Correction terms on local and global Z values
  28.         // http://forums-archive.secondlife.com/54/6a/153963/1.html
  29.  
  30.         vector zCorrectGlobal = <0.0, 0.0, 0.186>;
  31.         vector zCorrectLocal  = <0.0, 0.0, 0.4>;
  32.  
  33.         // A bit of scripting magic happens. This includes converting
  34.         // the rotation correction from degrees to quaternion format
  35.         // and offseting both the global and local Z-values by documented
  36.         // correction terms.
  37.  
  38.         rotation rotCorrection = llEuler2Rot(DEG_TO_RAD * angles);
  39.  
  40.         vector offset = (myPos + zCorrectGlobal) / rotCorrection - zCorrectLocal;
  41.         rotation rot  = llEuler2Rot(DEG_TO_RAD * myAngles) / rotCorrection;
  42.  
  43.  
  44.         // And we set the sit target
  45.  
  46.         llSitTarget (offset,rot);
  47.  
  48.     }
  49. }
Advertisement