Shortnote

This code selects uniform travel destinations within WANDER_DISTANCE from the origin point iPos inside a circle with z-altitude variation of ±2 meters. You will need to modify the script and change the WANDER_DISTANCE as well as the origin point iPos (alternatively, picked dynamically in state_entry with llGetPos).

Code

wanderer_uniform.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
 
// Set this to the centre or origin point from where all  
// random points will be picked.
vector _iPos = ZERO_VECTOR;
// Set this to the maximal distance distance in meters  
// from the origin point that the object will travel.
float WANDER_DISTANCE = 20;
 
integer _targetID = 0;
 
vector wasCirclePoint(float radius) {
    float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
    float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2);
    if(llPow(x,2) + llPow(y,2) <= llPow(radius,2))
        return _iPos + <x, y, llFrand(2)>;
    return wasCirclePoint(radius);
}
 
moveTo(vector position) {
    llTargetRemove(_targetID);
    _targetID = llTarget(position, .8);
    llLookAt(position, .6, .6);
    llMoveToTarget(position, 3);    
}
 
default
{
    state_entry() {
        _iPos = llGetPos();
        llSetStatus(STATUS_PHYSICS|STATUS_BLOCK_GRAB, TRUE);
        llVolumeDetect(TRUE);
        llSetForce(<0,0,9.81> * llGetMass(), 0);
        moveTo(wasCirclePoint(WANDER_DISTANCE));
    }
 
    at_target(integer tnum, vector targetpos, vector ourpos) {
        if(tnum != _targetID) return;
        moveTo(wasCirclePoint(WANDER_DISTANCE));
    }
}

secondlife/wanderer/examples/uniform.txt · Last modified: 2022/11/24 07:45 by 127.0.0.1

Access website using Tor Access website using i2p Wizardry and Steamworks PGP Key


For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.