Difference between revisions of "LlMoveToTarget"

From Second Life Wiki
Jump to navigation Jump to search
m (<lsl> tag to <source>)
 
(21 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{LSL Function/damping|tau}}{{LSL_Function
{{LSL_Function
|inject-2=
{{Issues/SVC-2441}}
{{LSL Function/physical|avatar=*}}
{{LSL Function/damping|tau}}
{{LSL Function/position|target|region=*}}
|func_id=70|func_sleep=0.0|func_energy=10.0
|func_id=70|func_sleep=0.0|func_energy=10.0
|func=llMoveToTarget
|func=llMoveToTarget
|p1_type=vector|p1_name=target|p1_desc=global position
|p1_type=vector|p1_name=target
|p2_type=float|p2_name=tau
|p2_type=float|p2_name=tau
|func_footnote=To stop the object from maintaining the '''target''' positions use {{LSLG|llStopMoveToTarget}}<br/>
|func_footnote=To stop the object from maintaining the {{LSLP|target}} positions use [[llStopMoveToTarget]]<br/>
To change the rotation in the same manner use {{LSLG|llLookAt}} or {{LSLG|llRotLookAt}}.
To change the rotation in the same manner use [[llLookAt]] or [[llRotLookAt]].
|func_desc=Critically damp to '''target''' in '''tau''' seconds (if the script is physical)
|func_desc=Critically damp to {{LSLP|target}} in {{LSLP|tau}} seconds (if the script is physical)
|return_text
|return_text
|spec
|spec
|caveats
|caveats=* When slowly moving to a lower Z value, beware of {{jira|SVC-2441}} - the sim will incorrectly move the object down faster than it should. That is, if you try moving to llGetPos() + <10, 10, -10>, you can end up at .z-10 several meters before getting to .x-10 and .y-10. There is a demo object in the JIRA which shows this effect.
* A llMoveToTarget call seems to persist even if physics is turned off. This is a useful trick on sluggish sims where the object can drop a bit between the call to enable physics and the call to llMoveToTarget - just do the llMoveToTarget before setting the object to physical.
* <code>[[llVecDist]]([[llGetPos]](), {{LSLPT|target}})</code> must be ''less than'' 65, or no movement will occur.
* Calling llMoveToTarget with a {{LSLP|tau}} of {{HoverText|0.0|zero}} or less will silently fail, and do nothing. The smallest functional {{LSLP|tau}} is 0.044444444 (two physics frames, 2/45).
|constants
|constants
|examples======Will Move your object to a position=====
|examples=Drop this script in a prim to have it follow the prim owner.
<pre>
<source lang="lsl2">
// script created by SpiritWolf Chikuwa
//
// /!\ PUBLIC DOMAIN /!\
// You can Copy/Mod/Trans
// Please, do not resell this script and give it full perm
// Just please leave this header intact
//
// Minor changes: (insert your name here and delete this comment if you do any mod of this script, thank you)
//
// Script start here:
 
default
default
{
{
     state_entry() //i use for this example a "state_entry", so the item move the first second you
     state_entry()
                  //rez it, but if needed you can change it with something else like "touch_start",
                  //it's will move only if you click on it, the alternative of "stat_entry" is
                  //"on_rez", the item will move only if rezzed, and now directly when the script
                  // will be compiled
     {
     {
         llSetStatus(STATUS_PHYSICS | STATUS_PHANTOM, TRUE); // of course llSetStatus must be used
        vector pos = llGetPos();
// with physic (we move the item, and phantom, it's not needed, but better if the object must
         llSetStatus(STATUS_PHYSICS, TRUE);
// don't collide with something on his way. Also, it's physic, so be carefull, only 31 prims
        // Little pause to allow server to make potentially large linked object physical.
// for an item allowed.
        llSleep(0.1);
         llMoveToTarget(<53.654,199.364,502.542>, 10); // this is waht we want the llMoveToTarget,
        llMoveToTarget(pos,0.4);
// will move the item to the axes X,Y,Z localy on the curent sim where is the prim, in the 10
        // Look for owner within 20 meters in 360 degree arc every 1 seconds.
// on this exampel is the speed, actually, the item will move slowly
         llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
    }
    sensor(integer total_number)
    {
        // Get position of detected owner
        vector pos = llDetectedPos(0);
        // Offset back one meter in X and up one meter in Z based on world coordinates.
        vector offset =<-1,0,1>;
//       offset = offset*llDetectedRot(0);  //Adding this line will orient the follower relative to the owner's position.
        pos+=offset;
        llMoveToTarget(pos,0.4);   
     }
     }
}
}
</pre>
</source>
|helpers
|helpers
|also_functions=*{{LSLG|llStopMoveToTarget}}
|also_functions={{LSL DefineRow||[[llStopMoveToTarget]]}}
*{{LSLG|llLookAt}}
{{LSL DefineRow||[[llLookAt]]}}
*{{LSLG|llRotLookAt}}
{{LSL DefineRow||[[llRotLookAt]]}}
*{{LSLG|llTarget}}
{{LSL DefineRow||[[llTarget]]}}
|also_tests
|also_tests
|also_events
|also_events

Latest revision as of 13:00, 22 January 2015

Summary

Function: llMoveToTarget( vector target, float tau );
0.0 Forced Delay
10.0 Energy

Critically damp to target in tau seconds (if the script is physical)

• vector target position in region coordinates
• float tau seconds to critically damp in

To stop the object from maintaining the target positions use llStopMoveToTarget
To change the rotation in the same manner use llLookAt or llRotLookAt.

Caveats

  • Only works in attachments and physics-enabled objects.
  • When slowly moving to a lower Z value, beware of SVC-2441 - the sim will incorrectly move the object down faster than it should. That is, if you try moving to llGetPos() + <10, 10, -10>, you can end up at .z-10 several meters before getting to .x-10 and .y-10. There is a demo object in the JIRA which shows this effect.
  • A llMoveToTarget call seems to persist even if physics is turned off. This is a useful trick on sluggish sims where the object can drop a bit between the call to enable physics and the call to llMoveToTarget - just do the llMoveToTarget before setting the object to physical.
  • llVecDist(llGetPos(), target) must be less than 65, or no movement will occur.
  • Calling llMoveToTarget with a tau of 0.0 or less will silently fail, and do nothing. The smallest functional tau is 0.044444444 (two physics frames, 2/45).

Examples

Drop this script in a prim to have it follow the prim owner.

default
{
    state_entry()
    {
        vector pos = llGetPos();
        llSetStatus(STATUS_PHYSICS, TRUE);
        // Little pause to allow server to make potentially large linked object physical.
        llSleep(0.1);
        llMoveToTarget(pos,0.4);
        // Look for owner within 20 meters in 360 degree arc every 1 seconds.
        llSensorRepeat("", llGetOwner(), AGENT, 20.0, PI,1.0);
    }
    sensor(integer total_number)
    {
        // Get position of detected owner
        vector pos = llDetectedPos(0);
        // Offset back one meter in X and up one meter in Z based on world coordinates.
        vector offset =<-1,0,1>;
//        offset = offset*llDetectedRot(0);  //Adding this line will orient the follower relative to the owner's position.
        pos+=offset;
        llMoveToTarget(pos,0.4);     
    }
}

See Also

Functions

•  llStopMoveToTarget
•  llLookAt
•  llRotLookAt
•  llTarget

Deep Notes

Signature

function void llMoveToTarget( vector target, float tau );