LlLookAt

De DigiWiki.

//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);
    }
}
  • 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);
    }
}
Outils personnels
  • Cette page a été consultée 902 fois.
donate
Google Ads