Difference between revisions of "LlRotLookAt"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(5 intermediate revisions by 3 users not shown)
Line 9: Line 9:
|p2_type=float|p2_name=strength
|p2_type=float|p2_name=strength
|p3_type=float|p3_name=damping
|p3_type=float|p3_name=damping
|func_footnote=To change the position in the same manner use [[llMoveToTarget]].  For physical objects a range between .2 and 1 is good for both parameters.  
|func_footnote=To change the position in the same manner, use [[llMoveToTarget]].  For physical objects a range between .2 and 1 is good for both parameters.  
|func_desc=Causes an object to smoothly rotate to {{LSLP|target_direction}} with {{LSLP|strength}} resistance at {{LSLP|damping}} force.
|func_desc=Causes an object to smoothly rotate to {{LSLP|target_direction}} with {{LSLP|strength}} resistance at {{LSLP|damping}} force.


Continues to face {{LSLP|target_direction}} until stopped with [[llStopLookAt]].
Maintains rotation {{LSLP|target_direction}} until stopped with [[llStopLookAt]].
|return_text
|return_text
|spec
|spec
|caveats=
|caveats=
* In Non-Physical objects this function operates effectively the same as [[llSetLocalRot]].
* In Non-Physical objects this function operates effectively the same as [[llSetLocalRot]].
* {{LSLP|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 {{LSLP|strength}} seems to be 0.0445 for the function to have any effect.
|constants
|constants
|examples=
|examples=
* Simple Example - point the prim's positive y axis towards a position on the sim
==== Point the prim's positive y axis (''<0.0, 1.0, 0.0>'') towards a position on the sim ====
<lsl>
<source lang="lsl2">
llRotLookAt(llRotBetween(<0.0,1.0,0.0>, llVecNorm(llDetectedPos(0)-llGetPos())),1.0,0.4); // Point Y in target_direction
//-- where vPosTarget is the global position of the object you want to "look" at
</lsl>
llRotLookAt( llRotBetween( <0.0,1.0,0.0>, llVecNorm( vPosTarget - llGetPos() ) ), 1.0, 0.4 ); // Point +Y axis towards vPosTarget
Void Singer explains:
</source>
''llRotBetween'' returns a scaled rotation, so if one term is a unit vector, it works out better if both are, hence the use of ''llVecNorm''
* '''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.


The code ''llDetectedPos(0)-llGetPos()'' is used to convert from global position to a local position.
==== Constraining the Rotation to One Axis ====
 
<source lang="lsl2">
* Constraining the Rotation to One Axis
       vector detected = llDetectedPos( 0 );
<lsl>
       vector detected = llDetectedPos(0);
       vector pos = llGetPos();
       vector pos = llGetPos();
       llRotLookAt(llRotBetween(<0.0,1.0,0.0>, llVecNorm(<detected.x,detected.y,pos.z>-pos)),1.0,0.4);
       llRotLookAt( llRotBetween( <0.0, 1.0, 0.0>, llVecNorm( <detected.x, detected.y, pos.z> - pos ) ), 1.0, 0.4 );
</lsl>
</source>
|helpers=
|helpers=
* If you want a (mostly) smooth constant rate of motion in a non-physical object try this instead
* If you want a (mostly) smooth ''constant'' (rather than damped) rate of motion in a non-physical object try this
<lsl>
<source lang="lsl2">
//-- Rotates Object to vRotTarget at vFltRate (in radians per second
//-- 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 < ~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
//-- vFltRate >= (PI * 5.0)rad/sec, (900deg/sec) will result in a single snap move to vRotTarget
uSteppedRotLookAt( rotation vRotTarget, float vFltRate){
uSteppedRotLookAt( rotation vRotTarget, float vFltRate ){
if ((integer)(vFltRate = (llAngleBetween( llGetLocalRot(), vRotTarget ) / (vFltRate / 5.0)))){
if ((integer)(vFltRate = (llAngleBetween( llGetLocalRot(), vRotTarget ) / (vFltRate / 5.0)))){
rotation vRotStep = llAxisAngle2Rot( llRot2Axis( vRotTarget / llGetLocalRot() ),
rotation vRotStep = llAxisAngle2Rot( llRot2Axis( vRotTarget / llGetLocalRot() ),
Line 47: Line 50:
do{
do{
llSetLocalRot( vRotStep * llGetLocalRot() );
llSetLocalRot( vRotStep * llGetLocalRot() );
}while( --vFltRate );
}while (--vFltRate);
}
}
llSetLocalRot( vRotTarget );
llSetLocalRot( vRotTarget );
} //-- for fixed time on any rotation try llKeyframeMotion
} //-- for fixed time on any rotation try llSetKeyframedMotion
</lsl>
</source>
|also_functions=
|also_functions=
{{LSL DefineRow||[[llLookAt]]}}
{{LSL DefineRow||[[llLookAt]]}}
{{LSL DefineRow||[[llStopLookAt]]}}
{{LSL DefineRow||[[llStopLookAt]]}}
{{LSL DefineRow||[[llSetPhysicsMaterial]]}}
{{LSL DefineRow||[[llSetKeyframedMotion]]}}
|also_events
|also_events
|also_tests
|also_tests
|also_articles
|also_articles
|notes=*For physical objects, {{LSLP|damping}} seems to be limited at 1.0; setting it to greater value has the same effect as if it was 1. Tested 21 October 2010 on server version 10.10.18.212360.
|notes
|permission
|permission
|negative_index
|negative_index

Latest revision as of 17:17, 26 March 2020

Summary

Function: llRotLookAt( rotation target_direction, float strength, float damping );

Causes an object to smoothly rotate to target_direction with strength resistance at damping force.

Maintains rotation target_direction until stopped with llStopLookAt.

• rotation target_direction
• float strength
• float damping seconds to critically damp in

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.
All Issues ~ Search JIRA for related Bugs

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 );

Useful Snippets

  • 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

Deep Notes

All Issues

~ Search JIRA for related Issues
   llRotLookAt & llLookAt do not update the object's bounding box

Signature

function void llRotLookAt( rotation target_direction, float strength, float damping );