Skip to content
lsl.devlsl.devLSL Dev

LlRotLookAt

Looking for the current API? Open the llRotLookAt reference →

Wiki description

Causes an object to smoothly rotate to target_direction with strength resistance at damping force.
Maintains rotation target_direction until stopped with llStopLookAt.

Function notes

To change the position in the same manner, use llMoveToTarget. For physical objects a range between .2 and 1 is good for both parameters.

Caveats

  • In Non-Physical objects this function operates effectively the same as llSetLocalRot.
  • damping seems to be capped at 1.0; greater values are reduced to 1.0 (Tested 21 October 2010 on server version 10.10.18.212360)
  • The minimum value for strength seems to be 0.0445 for the function to have any effect.

Examples

Point the prim's positive y axis (<0.0, 1.0, 0.0>) towards a position on the sim

//-- where vPosTarget is the global position of the object you want to "look" at
llRotLookAt( llRotBetween( <0.0,1.0,0.0>, llVecNorm( vPosTarget - llGetPos() ) ), 1.0, 0.4 ); // Point +Y axis towards vPosTarget
  • vPosTarget - llGetPos() converts the global coordinates of the objects, to a local distance and direction from the object pointing
  • Per llRotBetween article:
    • llRotBetween returns a scaled rotation, unless both inputs are equal magnitude (e.g. unit vector).
    • The use of llVecNorm reduces the magnitude to 1 (so that both are equal magnitude), preventing errors.

Constraining the Rotation to One Axis

      vector detected = llDetectedPos( 0 );
      vector pos = llGetPos();
      llRotLookAt( llRotBetween( <0.0, 1.0, 0.0>, llVecNorm( <detected.x, detected.y, pos.z> - pos ) ), 1.0, 0.4 );

Helper functions

  • If you want a (mostly) smooth constant (rather than damped) rate of motion in a non-physical object try this
//-- Rotates Object to vRotTarget 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
uSteppedRotLookAt( rotation vRotTarget, float vFltRate ){
	if ((integer)(vFltRate = (llAngleBetween( llGetLocalRot(), vRotTarget ) / (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 llSetKeyframedMotion

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/rotation

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.