Shortnote

A variation on the uniform wanderer with the addition that you can touch the primitive in order to toggle the wandering.

Code

wanderer_uniform.lsl
///////////////////////////////////////////////////////////////////////////
//  Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3      //
//  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  //
//  rights of fair usage, the disclaimer and warranty conditions.        //
///////////////////////////////////////////////////////////////////////////
 
///////////////////////////////////////////////////////////////////////////
//    Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3    //
///////////////////////////////////////////////////////////////////////////
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 <x, y, 0>;
    return wasCirclePoint(radius);
}
 
moveTo(vector position) {
    llTargetRemove(targetID);
    targetID = llTarget(position, .8);
    llLookAt(position, .6, .6);
    llMoveToTarget(position, dampening);    
}
 
// track targets
integer targetID = 0;
// dampening of movement
float dampening = 10;
// stray from origin
float radius = 5;
// the origin of the movement
vector origin = ZERO_VECTOR;
 
default {
    state_entry() {
        llOwnerSay("movement off");
        // set the origin to the current position
        origin = llGetPos();
        // stop all physics
        llSetStatus(STATUS_PHYSICS|STATUS_BLOCK_GRAB, FALSE);
        llVolumeDetect(FALSE);
    }
    touch_start(integer num) {
        state on;
    }
}
 
state on {
    state_entry() {
        llOwnerSay("movement on");
        // set the origin to the current position
        origin = llGetPos();
        // start physics
        llSetStatus(STATUS_PHYSICS|STATUS_BLOCK_GRAB, TRUE);
        // pass through solids but detect collision
        llVolumeDetect(TRUE);
        moveTo(origin + wasCirclePoint(radius));
    }
    touch_start(integer num) {
        state default;
    }
    at_target(integer tnum, vector targetpos, vector ourpos) {
        moveTo(origin + wasCirclePoint(radius));
    }
    collision_start(integer num) {
        moveTo(origin + wasCirclePoint(radius));
    }
    on_rez(integer num) {
        // set the origin to the current position
        origin = llGetPos();
        // stop all physics
        llSetStatus(STATUS_PHYSICS|STATUS_BLOCK_GRAB, FALSE);
        llVolumeDetect(FALSE);
    }
}

secondlife/wanderer/examples/uniform_touch_toggle.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.