Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llMoveToTarget() not working.

Kai Venkman
Will script for food...
Join date: 21 Feb 2006
Posts: 43
05-12-2006 10:02
Greetings,

I'm using the following code snippet to attempt to move an avatar. The code is in a HUD attachment:

CODE

state default
{
// other code here ...

sensor(integer total_number)
{
pos = llDetectedPos(0);
targetID = llTarget(pos, 0.5);
llMoveToTarget(pos, 10);
}

at_target(integer tnum, vector targetpos, vector ourpos)
{
llTargetRemove(targetID);
llStopMoveToTarget();
}
}


When executed the avatar doesn't move and consequently the at_target event never arrives (unless I manually move the avatar to the location, then the event fires). I've tried different tau values to no avail. Any idea what I'm doing wrong?

Thank you in advance!
Charles Granville
Registered User
Join date: 18 Mar 2006
Posts: 33
05-12-2006 11:37
Is the target within range? If it isn't, the script silently damps to the current position.
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
05-12-2006 12:44
Also, according to comments on the wiki, llMoveToTarget() will fail to function in an attachment if the script has been compiled while the object is attached. Detaching and reattaching it is supposed to fix this problem.
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Cross Lament
Loose-brained Vixen
Join date: 20 Mar 2004
Posts: 1,115
05-13-2006 21:56
I just tested this myself, and it's not working for me, either. I tried to make an attachment to jump on peoples' heads. :D

The at_target() event is not firing for some reason. Probably the best solution is to just forget the whole at_target() thing and run a timer that checks:

llVecMag( targetpos - llGetPos() ) < desired_target_distance, and call llStopMoveToTarget then.
_____________________
- Making everyone's day just a little more surreal -

Teeple Linden: "OK, where did the tentacled thing go while I was playing with my face?"
Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
05-15-2006 23:45
From: Kai Venkman
I'm using the following code snippet to attempt to move an avatar. The code is in a HUD attachment:

CODE

state default
{
}


Any idea what I'm doing wrong?


You need to replace "state default" with "state", then it will work for you. :)
I just tried it, and it works fine with that change and adding a sensor event. Like:
CODE

integer Target;
default
{
touch_start (integer Touches)
{
llSensor ("Avatar Name", NULL_KEY, AGENT, 96, PI);
}
sensor(integer total_number)
{
vector Pos = llDetectedPos (0);
Target = llTarget (Pos, 0.5);
llMoveToTarget (Pos, 1.0);
}
attach (key Avatar)
{
if (NULL_KEY == Avatar)
{
llTargetRemove (Target);
llStopMoveToTarget ();
}
}
at_target(integer tnum, vector targetpos, vector ourpos)
{
llTargetRemove (Target);
llStopMoveToTarget ();
}
}