Advertisement
Dorex

Untitled

Sep 30th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. setTargetRandomPosition(integer lookInMoveDirection){
  2.  
  3. rotation deltaRotation = ZERO_ROTATION ;
  4.  
  5. if (!stopStartAll){
  6.  
  7. vector currentPosition = llGetPos();
  8. //
  9. // don't allow object to go below the z position it was rezzed at
  10. //
  11. float zPos = fRandPlusMinus(travelDistance.z);
  12. if (zPos + rezPosition.z < rezPosition.z) zPos = 0;
  13. //
  14. // how much are we going to move this round
  15. //
  16. vector deltaPosition = <fRandPlusMinus(travelDistance.x), fRandPlusMinus(travelDistance.y), zPos>;
  17.  
  18. deltaPosition.x = keepInBounds(currentPosition.x, deltaPosition.x, rezPosition.x, targetBoundary.x);
  19. deltaPosition.y = keepInBounds(currentPosition.y, deltaPosition.y, rezPosition.y, targetBoundary.y);
  20. deltaPosition.z = keepInBounds(currentPosition.z, zPos, rezPosition.z, targetBoundary.z);
  21.  
  22.  
  23. vector lookAtPos = currentPosition + deltaPosition;
  24.  
  25. if (lookInMoveDirection && !targetStayLevel) {
  26. llLookAt(lookAtPos, 3.0, 1.0);
  27. //vector newV = lookAtPos - currentPosition;
  28. //llSetRot(llRotBetween( <0,0,1>, llVecNorm(newV)));
  29.  
  30. } else if (targetStayLevel) {
  31. llLookAt(<lookAtPos.x, lookAtPos.y, currentPosition.z>, 3.0, 1.0);
  32. }
  33. //
  34. // how far are we moving
  35. //
  36. float distance = llVecDist(ZERO_VECTOR, deltaPosition);
  37. //
  38. // how long do we want to take to get there
  39. //
  40. float timeValue = frameDelta(distance/ travelSpeed);
  41. //
  42. isMoving = TRUE;
  43. llSetKeyframedMotion(
  44. [deltaPosition, deltaRotation , timeValue],
  45. [KFM_DATA, KFM_TRANSLATION|KFM_ROTATION, KFM_MODE, KFM_FORWARD]);
  46.  
  47. }
  48. }
  49.  
  50. float frameDelta(float time)
  51. {
  52. // take the delta times and align them to SL frames
  53. time = llRound(time/(1/45.0))/45.0;
  54. if (time > 0.12)
  55. return time;
  56. return 0.133333;
  57. }
  58.  
  59. float keepInBounds(float currentPosition, float delta, float startValue, float maxValue){
  60. //
  61. // if currentPosition + delta is outside the bounding box, reverse the distance to move to try
  62. // and keep within the bounds
  63. //
  64. if (currentPosition + delta < startValue + maxValue && currentPosition + delta > startValue - maxValue) return delta;
  65. return delta * -1;
  66. }
  67.  
  68. float fRandPlusMinus(float value){
  69. if (value == 0) return 0;
  70. // return from -value to +value
  71. value = llFrand(value - 1) + 1;
  72. if (llFrand(100) + 1 > 50) value = -value;
  73. return value;
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement