Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to create a user-defined XY bound box

Luke Ramona
Registered User
Join date: 3 Apr 2005
Posts: 32
05-18-2005 16:41
Hi,

I am trying to create a script to move a physical object with the llMoveToTarget() function but need to create a random vector within a user defined boundary for the object to move to. The object will remain on the same Z coordinate where the user places or edits it to, so it's only the X and Y coordinates that need to change in the target vector.

The user positions the object in the first corner of the bounding box then says "setpos1" and the script stores that vector, then the user moves the object to the opposite corner of the area that want it to move around in and says "setpos2" and the script stores that vector. Now how does the script go about generating random vectors for each llMoveToTarget() function that is called, vector which will remain inside those defined corners of the area?

I seem to be able to get it to move in a positive direction, but not a negative direction. And also it always goes out of the boundary area. I tried to adapt the Wiki LibraryScript "Create a Flying Pet" but it didn't work too well.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-18-2005 17:41
Okay then. Pick a random position in the two-dimensional box?

That's easy.

CODE
vector one = <1,1,0>;
vector two = <2,2,0>;

// Assumption: Vector Two is always greater than or equal to Vector One
// This will work even if it's the reverse
vector diff = two - one;

// Here's the random position
vector random = one + <llFrand(1.0) * diff.x,llFrand(1.0) * diff.y,llFrand(1.0) * diff.z>;
_____________________
---
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
05-19-2005 05:35
I suspect Jeff's reply will always put it on the diagonal...

different llFrand(1.0) calls for the x and y components will let it be anywhere.

diff.x * llFrand(1.0)
diff.y * llFrand(1.0)

then add to vector 1....
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-19-2005 06:22
Whoops! You're right. Let me fix that. :D
_____________________
---
Luke Ramona
Registered User
Join date: 3 Apr 2005
Posts: 32
05-19-2005 10:48
hehe.. I haven't tried it yet but I'm sure it will work. Knew it was something easy like that.. just got my brain all messed up with the calculations of everything else and wasn't thinking simple enough.
Tya Fallingbridge
Proud Prim Whore
Join date: 28 Aug 2003
Posts: 790
06-20-2005 15:48
From: Jeffrey Gomez
Okay then. Pick a random position in the two-dimensional box?

That's easy.

CODE
vector one = <1,1,0>;
vector two = <2,2,0>;

// Assumption: Vector Two is always greater than or equal to Vector One
// This will work even if it's the reverse
vector diff = two - one;

// Here's the random position
vector random = one + <llFrand(1.0) * diff.x,llFrand(1.0) * diff.y,llFrand(1.0) * diff.z>;



I am getting syntax errors... :(
_____________________

Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
06-20-2005 16:51
That's because the code is a stub. You need to enclose it in some form of event to make it work.

Here's a good read:

http://secondlife.com/badgeo/wakka.php?wakka=tutorial
_____________________
---
Tya Fallingbridge
Proud Prim Whore
Join date: 28 Aug 2003
Posts: 790
06-21-2005 15:35
From: Jeffrey Gomez
That's because the code is a stub. You need to enclose it in some form of event to make it work.

Here's a good read:

http://secondlife.com/badgeo/wakka.php?wakka=tutorial



OK its way beyond me....
_____________________

Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
06-21-2005 15:50
It means just do this.

CODE
vector here = <0,0,0>; 
default
{
state_entry()
{
here = llGetPos();
}

touch_start(integer total_number)
{
vector one = <1,1,0>;
vector two = <2,2,0>;

// Assumption: Vector Two is always greater than or equal to Vector One
// This will work even if it's the reverse
vector diff = two - one;

// Here's the random position
vector random = one + <llFrand(1.0) * diff.x,llFrand(1.0) * diff.y,llFrand(1.0) * diff.z>;
llSetPos(here + random);
}
}
_____________________
---