Difference between revisions of "LlFleeFrom"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 42: Line 42:
{
{
vector last_touched_pos_now = llList2Vector(llGetObjectDetails(last_touched_key, [OBJECT_POS]), 0);
vector last_touched_pos_now = llList2Vector(llGetObjectDetails(last_touched_key, [OBJECT_POS]), 0);
if ( llVecDist(owner_pos, last_owner_pos) > 1 )
if ( llVecDist(last_touched_pos, last_touched_pos_now) > 1 )
{
{
last_touched_pos = last_touched_pos_now;
last_touched_pos = last_touched_pos_now;

Revision as of 09:14, 11 July 2012

Summary

Function: llFleeFrom( vector position, float distance, list options );

Directs a character to keep a specific distance from a specific position in the region or adjacent regions.

• vector position position in region coordinates from which to flee.
• float distance Distance in meters to flee from position.
• list options No options available at this time.

Caveats

  • Must use llCreateCharacter or script won't compile.
  • The position to flee from must be near the nav mesh; otherwise, this behavior will fail and trigger path update with PU_FAILURE_INVALID_GOAL.
  • If you want to avoid an agent or object as per the example below, it's much more elegant and less sim resource intensive to use llEvade instead.

Examples

<lsl> vector last_touched_pos; key last_touched_key;

default { state_entry() {

}

touch_start(integer total_number) { last_touched_key = llDetectedKey(0); last_touched_pos = llList2Vector(llGetObjectDetails(last_touched_key, [OBJECT_POS]), 0); llFleeFrom(last_touched_pos, 10, []); llSetTimerEvent(0.2); }

timer() { vector last_touched_pos_now = llList2Vector(llGetObjectDetails(last_touched_key, [OBJECT_POS]), 0); if ( llVecDist(last_touched_pos, last_touched_pos_now) > 1 ) { last_touched_pos = last_touched_pos_now; llFleeFrom(last_touched_pos, 10, []); } } }

</lsl>

Notes

The position vector can be set outside the current region by using extended range region coordinates: e.g., to avoid the SE corner of the region to the East of the current one, you could <lsl>llFleeFrom(<0.0, 512.0, 0.0>, 20.0, []);</lsl>

Deep Notes

Signature

function void llFleeFrom( vector position, float distance, list options );