Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple Avatar Movement via Coordinates (incomplete)

Toneless Tomba
(Insert Witty Title Here)
Join date: 13 Oct 2004
Posts: 241
04-21-2005 20:49
Vectors & rotatons make my head spin. I'm trying to make a simple avatar movement script using coordinates within the same sim using an attached object. Problem is that llMoveTarget fails silently for distances larger than 60m. Could someone fill complete the multiplemoves() function I will be much in debt to you. :D Thank you in advance.


CODE
vector target;   //  Target vector within the same sim
integer removeListen;
integer targetID;
float tau = 1.5;
vector currentPos;


multiplemoves(vector location) // Will use llMoveToTarget() multiple times to reach final destatantion
{

// Please help I have no clue....

}


default
{
attach(key attached)
{
if (attached != NULL_KEY) // object has been //attached//
{
state ready;
}
}
}

state ready
{
state_entry()
{
llOwnerSay("Ready. Please touch me to enter coordinate");
}

touch_start(integer num_detected) //Touch attached object then say coordinates in region
{
llOwnerSay("Please say the coordinates of the location:");
removeListen = llListen(0, "", llGetOwner(), "");
llSetTimerEvent(30.0);
}

listen(integer channel, string name, key id, string message)
{
llSetTimerEvent(0);
llListenRemove(removeListen);
target = (vector)message;
state move;
}

at_target(integer tnum, vector targetpos, vector ourpos) // Informs owner arrived, clears target & stops moving.
{
llOwnerSay("Destination reached...");
llTargetRemove(targetID);
llStopMoveToTarget();
}

attach(key attached)
{
if (attached == NULL_KEY) // object has been detached//
{
llSetTimerEvent(0);
llOwnerSay("Detached.");
state default;
}
}

timer() //Listen Timeout after 30 seconds
{
llSetTimerEvent(0);
llListenRemove(removeListen);
llOwnerSay("Timed Out");
}
}

state move
{
state_entry()
{
llSetTimerEvent(5);
currentPos = llGetPos();
targetID = llTarget( target, 1.0 ); // Set location for AtTarget event within range of 1.0m
if (llVecDist(llGetPos(), target) > 60) multiplemoves(target); // llMoveToTarget() maximum distance is 60m otherwise multiple moves required.
else llMoveToTarget(target, tau);
}
at_target(integer tnum, vector targetpos, vector ourpos) // Informs owner arrived, clears target & stops moving.
{
llOwnerSay("Destination reached...");
llTargetRemove(targetID);
llStopMoveToTarget();
llSetTimerEvent(0);
state ready;
}

attach(key attached)
{
if (attached == NULL_KEY) // object has been detached
{
llOwnerSay("Detached.");
llSetTimerEvent(0);
state default;
}
}

timer()
{
vector After5secPos = llGetPos();
if (llVecDist(currentPos, After5secPos) < 2.0) //Checks to see if got stuck, if hasn't moved more than 2.0m in 5 sec will remove targets, stop moving & return to state ready
{
llOwnerSay("Stuck..");
llTargetRemove(targetID);
llStopMoveToTarget();
llSetTimerEvent(0);
state ready;
}
currentPos = After5secPos;
}
}
Toneless Tomba
(Insert Witty Title Here)
Join date: 13 Oct 2004
Posts: 241
04-22-2005 08:44
Maybe a simpler question is need to be asked. Say I want to go from point A to point B within the same sim and it's farther than 60m using llMoveTarget how do I figure that out?
Brian Mifflin
Scripting Addict
Join date: 15 Dec 2004
Posts: 182
04-22-2005 08:58
CODE

if(llVecMag(vFinalTarget - vCurrentPosition) > 60) {
vector vDirection = llVecNorm(vFinalTarget - vCurrentPosition);
vector vNextTarget = (vDirection * 60) + vCurrentPosition;
llMoveToTarget(vNextTarget, fTime);
} else {
llMoveToTarget(vFinalTarget, fTime);
}


Test to see if it is longer than 60m, if so, just travel 60m in that direction. When you get an at_target event (use llTarget) then move to the next Target. You can use a stack, push & pop a list of targets, or use global variables and states.
_____________________
Toneless Tomba
(Insert Witty Title Here)
Join date: 13 Oct 2004
Posts: 241
Version that works
04-22-2005 11:14
Thank You, that did the trick. For anyone interested this is a simple movement script for an attached object that needs to be touched to be activated, then listens for coordinates (must be in same sim). Goes in straight line, no intelligent pathfinding, if it gets stuck it will give you controls back after 10 sec.

CODE
vector target;   //  Target vector within the same sim
integer removeListen;
integer targetID;
float tau = 1.5;
vector currentPos;


multiplemoves(vector location) // Because target is farther than 60m it will move 60m in that direction
{
vector vDirection = llVecNorm(location - currentPos);
vector vNextTarget = (vDirection * 60) + currentPos;
llMoveToTarget(vNextTarget, tau);
targetID = llTarget(vNextTarget, 1.0);
}


default
{
attach(key attached)
{
if (attached != NULL_KEY) // object has been //attached//
{
state ready;
}
}
}

state ready
{
state_entry()
{
llOwnerSay("Ready. Please touch me to enter coordinate");
}

touch_start(integer num_detected) //Touch attached object then say coordinates in region
{
llOwnerSay("Please say the coordinates of the location:");
removeListen = llListen(0, "", llGetOwner(), "");
llSetTimerEvent(30.0);
}

listen(integer channel, string name, key id, string message)
{
llSetTimerEvent(0);
llListenRemove(removeListen);
target = (vector)message;
state move;
}

attach(key attached)
{
if (attached == NULL_KEY) // object has been detached//
{
llSetTimerEvent(0);
llOwnerSay("Detached.");
state default;
}
}

timer() //Listen Timeout after 30 seconds
{
llSetTimerEvent(0);
llListenRemove(removeListen);
llOwnerSay("Timed Out");
}

}

state move
{
state_entry()
{
llSetTimerEvent(10);
currentPos = llGetPos();
if (llVecDist(currentPos, target) > 60) multiplemoves(target); // llMoveToTarget() maximum distance is 60m otherwise multiple moves required.
else
{
targetID = llTarget( target, 1.0 ); // Set location for AtTarget event within range of 1.0m
llMoveToTarget(target, tau);
}
}
at_target(integer tnum, vector targetpos, vector ourpos) // Checks to see if arrived at original target then removes target & stops moving otherwise continues closer to target
{
currentPos = llGetPos();
if (llVecDist(currentPos, target) > 60) multiplemoves(target); // llMoveToTarget() maximum distance is 60m otherwise multiple moves required.
else
{
if (llVecDist(currentPos, target) > 1)
{
targetID = llTarget( target, 1.0 ); // Set location for AtTarget event within range of 1.0m
llMoveToTarget(target, tau);
}
else
{
llOwnerSay("Destination reached...");
llTargetRemove(targetID);
llStopMoveToTarget();
state ready;
}
}
}

attach(key attached)
{
if (attached == NULL_KEY) // object has been detached
{
llOwnerSay("Detached.");
llSetTimerEvent(0);
state default;
}
}

timer()
{
vector After5secPos = llGetPos();
if (llVecDist(currentPos, After5secPos) < 2.0) //Checks to see if got stuck, if hasn't moved more than 2.0m in 10 sec will remove targets, stop moving & return to state ready
{
llOwnerSay("Stuck..");
llTargetRemove(targetID);
llStopMoveToTarget();
llSetTimerEvent(0);
state ready;
}
currentPos = After5secPos;
}

state_exit()
{
llSetTimerEvent(0);
}
}
Brian Mifflin
Scripting Addict
Join date: 15 Dec 2004
Posts: 182
04-22-2005 11:31
Glad I could help, isn't it great we have the llOwnerSay now? :D
_____________________
Toneless Tomba
(Insert Witty Title Here)
Join date: 13 Oct 2004
Posts: 241
04-22-2005 11:39
llOwnerSay is great! I haven't tested it but can everyone else see the swirly things when it does an llOwnerSay?
Brian Mifflin
Scripting Addict
Join date: 15 Dec 2004
Posts: 182
04-22-2005 11:45
From: Toneless Tomba
llOwnerSay is great! I haven't tested it but can everyone else see the swirly things when it does an llOwnerSay?


No, only you can see them.
_____________________