KanEd-Test09.lsl 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. vector startPos;
  2. vector curPos;
  3. vector curForce;
  4. integer second;
  5. default
  6. {
  7. state_entry()
  8. {
  9. llSay( 0, "Hello, Avatar! Touch to launch me straight up.");
  10. llSetStatus( 1, TRUE );
  11. startPos = < 0, 0, 0 >;
  12. }
  13. touch_start(integer total_number)
  14. {
  15. startPos = llGetPos();
  16. curPos = startPos;
  17. curForce = < 0, 0, 0 >;
  18. second = 0;
  19. llSetColor( < 1.0, 0.0, 0.0 > , ALL_SIDES ); // set color to red.
  20. float objMass = llGetMass();
  21. float Z_force = 10.2 * objMass;
  22. llSetForce( < 0.0, 0.0, Z_force >, FALSE );
  23. llSay( 0, "Force of " + (string)Z_force + " being applied." );
  24. llSetTimerEvent(1);
  25. }
  26. timer()
  27. {
  28. second++;
  29. curPos = llGetPos();
  30. float curDisplacement = llVecMag( curPos - startPos );
  31. if( ( curDisplacement > 30. ) && // then object is too far away, and
  32. ( llGetForce() != < 0.0, 0.0, 0.0 > ) ) // force not already zero,
  33. { // then let gravity take over, and change color to green.
  34. llSetForce( < 0.0, 0.0, 0.0 >, FALSE );
  35. llSetColor( < 0, 1.0, 0 >, ALL_SIDES );
  36. llSay( 0, "Force removed; object in free flight." );
  37. }
  38. if ( second > 19 ) // then time to wrap this up.
  39. {
  40. // turn object blue and zero force to be safe....
  41. llSetColor( < 0, 0, 1.0 >, ALL_SIDES ); // change color to blue.
  42. llSetForce( < 0, 0, 0 >, FALSE );
  43. // ...move object back to starting position...
  44. // ...after saving current status of Physics attribute.
  45. integer savedStatus = llGetStatus( 1 );
  46. llSetStatus( 1, FALSE ); // turn physics off.
  47. while ( llVecDist( llGetPos(), startPos ) > 0.001)
  48. {
  49. llSetPos( startPos );
  50. }
  51. llSetStatus( 1, savedStatus ); // restore Physics status.
  52. //...and then turn color to black and Reset the script.
  53. llSetColor( < 1, 1, 1 >, ALL_SIDES );
  54. llSetTimerEvent( 0 ); // turn off timer events.
  55. llSay( 0, "Done and resetting script." );
  56. llResetScript(); // return object to ready state.
  57. }
  58. }
  59. }