Skip to content
lsl.devlsl.devLSL Dev

LlLookAt

Looking for the current API? Open the llLookAt reference →

Wiki description

Cause object to point its up axis (positive z) towards target, while keeping its forward axis (positive x) below the horizon.
Continues to track target until llStopLookAt is called.

Function notes

To change the position in the same manner use llMoveToTarget.

Specification

Strength is an inverse value meaning lower values cause the object to turn faster. Damping smooths the objects movements out preventing jitter or sharp movements. Object size, mass, and shape do not effect the function other than a large physical object that is resting on or colliding with other objects might not be able to turn correctly or fully.

Caveats

  • Object must be physical or this will do nothing.
  • If the prim is not the root, then target will need correction for the root prim's rotation (see example below).
  • If the object is an attachment, then target will need correction for the wearer's rotation.
  • Low strength values paired with low damping can cause the object to wobble and never fully face the target.

Examples

//Causes Object to look at nearest Avatar.
default
{
    state_entry()
    {
        llSensorRepeat("", "", AGENT, 20.0, PI, 0.2);
    }

    sensor(integer total_number)
    {
        llLookAt( llDetectedPos(0) + <0.0, 0.0, 1.0>, 3.0, 1.0 );
    }
}
// Same as above, but for use inside a child prim or the root of an attachment.
// Make the child or attachment look at nearest Avatar.

default
{
    state_entry()
    {
        llSensorRepeat("", "", AGENT, 20.0, PI, 0.2);
    }
 
    sensor(integer total_number)
    {
        vector p = llGetPos();
        llLookAt(p + (llDetectedPos(0) + <0.0, 0.0, 1.0> - p) / llGetRootRotation(), 3.0, 1.0);
    }
}

Helper functions

  • If you want a (mostly) smooth, one time, constant rate of motion, (using the x axis) in a non-physical object try this instead...
//-- rotate objects x axis toward vPosTarget (local offset), at vFltRate (in radians per second)
//-- vFltRate < ~0.00000003rad/sec, (~0.00002deg/sec) will result in errors (and is just too slow anyway)
//-- vFltRate >= (PI * 5.0)rad/sec, (900deg/sec) will result in a single snap move to vRotTarget
uSteppedLookAt( vector vPosTarget, float vFltRate ){
	rotation vRotTarget = llRotBetween( <1.0, 0.0, 0.0>,  vPosTarget );
	if ((integer)(vFltRate = llAcos( (vPosTarget = llVecNorm( vPosTarget )) *
	                                 (<1.0, 0.0, 0.0> * llGetLocalRot()) ) / (vFltRate / 5.0))){
		rotation vRotStep = llAxisAngle2Rot( llRot2Axis( vRotTarget / llGetLocalRot() ),
		                    (1.0 / vFltRate) * llRot2Angle( vRotTarget / llGetLocalRot() ) );
		vFltRate = (integer)vFltRate;
		do{
			llSetLocalRot( vRotStep * llGetLocalRot() );
		}while( --vFltRate );
	}
	llSetLocalRot( vRotTarget );
} //-- for fixed time on any rotation try llKeyframeMotion
  • If you want to use the LookAt function on a linked object...
LinkedLookAt( vector Target){
    rotation rotvec = llRotBetween(<0,1,0>,llVecNorm((Target - llGetPos())));
    rotation rotbet = rotvec/llGetRootRotation();
    llSetRot(rotbet);
}

default
{
    state_entry()
    {
        llSensorRepeat("", "", AGENT, 20.0, PI, 1.0);
    }

    sensor(integer total_number)
    {
        vector p = llDetectedPos(0);
        LinkedLookAt(p);
    }
}

See also: functions

Shared wiki helpers

The original page also injects shared parameter notes, caveats or issue information through these helpers. Their conditional MediaWiki logic is not reproduced here; inspect the preserved helper source for additional material.

Template:Issues/SVC-1903

Original shared helper source (conditional wiki logic is not evaluated)
{{Issues|SVC-1903|type=bug|[[llRotLookAt]] & [[llLookAt]] do not update the object's bounding box|resolution=fixed}}

Template:LSL Function/damping

Original shared helper source (conditional wiki logic is not evaluated)
{{LSL Injection Test}}{{#if:

{{#vardefine:header_footnote|{{#var:header_footnote}}}}

{{#vardefine:p_{{{1|}}}_desc|seconds to critically damp in}}

{{#if:{{{1|}}}|{{#vardefine:hidden-text|{{#var:hidden-text}}{{LSLC|Damping}}}}}}

}}<includeonly>{{#if:{{{1|}}}|{{LSLC|Damping}}}}</includeonly><noinclude>
{| {{Prettytable}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_{{{1|}}}_desc}}
|-
{{VarPair|p_{{{1|}}}_hover}}
|-
{{VarPair|header_footnote}}
|}
</noinclude>

Template:LSL Function/strength

Original shared helper source (conditional wiki logic is not evaluated)
{{LSL Injection Test}}{{#if:

{{#vardefine:p_{{{1|}}}_desc|}}

{{#vardefine:p_{{{1|}}}_hover|}}

{{#if:{{{1|}}}|{{#vardefine:hidden-text|{{#var:hidden-text}}{{LSLC|Strength}}}}}}

}}<includeonly>{{#if:{{{1|}}}|{{LSLC|Strength}}}}</includeonly><noinclude>
{| {{Prettytable}}
|-{{Hl2}}
! #var
! value
|-
{{VarPair|p_{{{1|}}}_desc}}
|-
{{VarPair|p_{{{1|}}}_hover}}
|}
</noinclude>

Template:LSL Function/position

Original shared helper source (conditional wiki logic is not evaluated)
{{LSL Injection Test}}<noinclude>
This template is to be used to specify setup the description for position like parameters (offsets, positions, points, etc.).

Right now it's pretty basic and easy to edit. I'm wondering if these functions should be in a position parameter specific category.

====TODO====
* add clamping flag and verbiage for out of region/range coordinates.
</noinclude>{{#if:

{{#if:{{{region|}}}|
  {{#if:{{{local|}}}|

    {{#vardefine:p_{{{1|}}}_desc|position in {{HoverLink|Viewer coordinate frames#Region|Origin is the origin of the region which {{String|owns}} the object.|region}} or [[Viewer coordinate frames#Local|local coordinates]] depending upon the situation{{{desc|}}}}}

    {{#vardefine:p_{{{1|}}}_hover|position in region or local coordinates depending upon the situation{{#if:{{{hover|}}}|{{{hover|}}}|{{{desc|}}}}}}}

  |
    {{#ifeq:{{{1|}}}|point|

      {{#vardefine:p_{{{1|}}}_desc|A point in {{HoverLink|Viewer coordinate frames#Region|Origin is the origin of the region which {{String|owns}} the object.|region-local}} space{{#ifeq:{{{region|}}}|noZ|&#32;(z component is ignored)}}{{{desc|}}}}}

      {{#vardefine:p_{{{1|}}}_hover|A point in region-local space{{#ifeq:{{{region|}}}|noZ|&#32;(z component is ignored)}}{{#if:{{{hover|}}}|{{{hover|}}}|{{{desc|}}}}}}}

    |

      {{#vardefine:p_{{{1|}}}_desc|position in {{HoverLink|Viewer coordinate frames#Region|Origin is the origin of the region which {{String|owns}} the object.|region coordinates}}{{#ifeq:{{{region|}}}|noZ|&#32;(z component is ignored)}}{{{desc|}}}}}

      {{#vardefine:p_{{{1|}}}_hover|position in region coordinates{{#ifeq:{{{region|}}}|noZ|&#32;(z component is ignored)}}{{#if:{{{hover|}}}|{{{hover|}}}|{{{desc|}}}}}}}

    }}
  }}
|
  {{#if:{{{local|}}}|

    {{#ifeq:{{{1|}}}|offset|

      {{LSL Function/offset|{{{1|}}}|local={{{local}}}}}

    |

      {{#vardefine:p_{{{1|}}}_desc|position in [[Viewer coordinate frames#Local|local coordinates]]{{{desc|}}}}}

      {{#vardefine:p_{{{1|}}}_hover|position in local coordinates{{#if:{{{hover|}}}|{{{hover|}}}|{{{desc|}}}}}}}

    }}
  }}
}}

}}
Original wiki source

Some wiki templates and tables need their original context. View this article on the Second Life Wiki. Technical wording and examples are retained from the source; historical guidance may differ from current behavior.