Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setTargetRandomPosition(integer lookInMoveDirection){
- rotation deltaRotation = ZERO_ROTATION ;
- if (!stopStartAll){
- vector currentPosition = llGetPos();
- //
- // don't allow object to go below the z position it was rezzed at
- //
- float zPos = fRandPlusMinus(travelDistance.z);
- if (zPos + rezPosition.z < rezPosition.z) zPos = 0;
- //
- // how much are we going to move this round
- //
- vector deltaPosition = <fRandPlusMinus(travelDistance.x), fRandPlusMinus(travelDistance.y), zPos>;
- deltaPosition.x = keepInBounds(currentPosition.x, deltaPosition.x, rezPosition.x, targetBoundary.x);
- deltaPosition.y = keepInBounds(currentPosition.y, deltaPosition.y, rezPosition.y, targetBoundary.y);
- deltaPosition.z = keepInBounds(currentPosition.z, zPos, rezPosition.z, targetBoundary.z);
- vector lookAtPos = currentPosition + deltaPosition;
- if (lookInMoveDirection && !targetStayLevel) {
- llLookAt(lookAtPos, 3.0, 1.0);
- //vector newV = lookAtPos - currentPosition;
- //llSetRot(llRotBetween( <0,0,1>, llVecNorm(newV)));
- } else if (targetStayLevel) {
- llLookAt(<lookAtPos.x, lookAtPos.y, currentPosition.z>, 3.0, 1.0);
- }
- //
- // how far are we moving
- //
- float distance = llVecDist(ZERO_VECTOR, deltaPosition);
- //
- // how long do we want to take to get there
- //
- float timeValue = frameDelta(distance/ travelSpeed);
- //
- isMoving = TRUE;
- llSetKeyframedMotion(
- [deltaPosition, deltaRotation , timeValue],
- [KFM_DATA, KFM_TRANSLATION|KFM_ROTATION, KFM_MODE, KFM_FORWARD]);
- }
- }
- float frameDelta(float time)
- {
- // take the delta times and align them to SL frames
- time = llRound(time/(1/45.0))/45.0;
- if (time > 0.12)
- return time;
- return 0.133333;
- }
- float keepInBounds(float currentPosition, float delta, float startValue, float maxValue){
- //
- // if currentPosition + delta is outside the bounding box, reverse the distance to move to try
- // and keep within the bounds
- //
- if (currentPosition + delta < startValue + maxValue && currentPosition + delta > startValue - maxValue) return delta;
- return delta * -1;
- }
- float fRandPlusMinus(float value){
- if (value == 0) return 0;
- // return from -value to +value
- value = llFrand(value - 1) + 1;
- if (llFrand(100) + 1 > 50) value = -value;
- return value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement