Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

random movement...

Schuyler Kent
Registered User
Join date: 30 Jan 2005
Posts: 22
03-06-2006 21:29
Hello -

I am using this script, I do not know where it came from, to have a little ball roam my platform. I figured out how to stopit form moving up and down, but it seems the prim it's self rotates as it goes. I would love to:

1. be able to stop the prim from rotating while it randomly moves.
2. be able determine the "front" so it always facing frint and turns before moving ina different direction. invision "tank tracks"
3. be able to sit on the object to ride it.

any help? is this a good start?

CODE

float radius = 15.0; //distance from starting point to wonder
float timeout = 7.0; //time between movement changes
float max_dist = 7.0; //max distance to move on x/y axis per timeout

vector start; //starting location, found on start/rez

//randomly move somewhere within the defined circle
random_move(){
vector pos; //new position
float dist; //distance from center

//calculate the new position
do{
//start with the current position
pos = llGetPos();
//randomly update x/y cords
pos.x += llFrand(max_dist * 2)-max_dist;
pos.y += llFrand(max_dist * 2)-max_dist;
//pos.z += llFrand(max_dist * 2)-max_dist;
//calculate dist = sqrt( diff(x)^2 + diff(y)^2 )
dist = ((pos.x - start.x) * (pos.x - start.x)) +
((pos.y - start.y) * (pos.y - start.y)) +
//((pos.z - start.z) * (pos.z - start.z));
dist = llSqrt(dist);

//if we are outside of the circles radius try again
}while(dist > radius);

//move to the new point
llMoveToTarget(pos,timeout);
}

default{
state_entry(){
//get starting point and init timer
start = llGetPos();
llSetTimerEvent(timeout);
//move the object
random_move();
}
on_rez(integer i){
//get starting point and init timer
start = llGetPos();
llSetTimerEvent(timeout);
//move the object
random_move();
}
timer(){
//move the object
random_move();
}
}
Paul Wardark
Wait, what?
Join date: 10 Jan 2009
Posts: 383
06-12-2009 17:36
I'm going to bump this old post up because I'm now using this same script, and having the same problem. Can't get the object to "face" the direction it's moving in.