LSL Wiki Mirror 10-5-2006: llLookAt

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings ::
llLookAt(vector target, float strength, float damping)

Causes the object to point the up (Z) axis toward target. Good strength values are around half the mass of the object and good damping values are less than 1/10th of the strength. Asymmetrical shapes require smaller damping. Calling llStopLookAt cancels the function.

This function works for both physical and non-physical objects.

Unlike llSetRot this function will rotate the object around its center of gravity.

Note: within the LSL editor, the tooltip for llLookAt reads "llLookAt(vector target, F32 strength, F32 damping)". F32 refers to a 32-bit float. In LSL, all floats are 32-bit.

Just in case you need an axis other then the up axis pointed at a target, here's a useful code snippet:
// AXIS_* constants, represent the unit vector 1 unit on the specified axis.
vector AXIS_UP = <0,0,1>;
vector AXIS_LEFT = <0,1,0>;
vector AXIS_FWD = <1,0,0>;

// getRotToPointAxisAt()
// Gets the rotation to point the specified axis at the specified position.
// @param axis The axis to point. Easiest to just use an AXIS_* constant.
// @param target The target, in region-local coordinates, to point the axis at.
// @return The rotation necessary to point axis at target.
// Created by Ope Rand, modifyed by Christopher Omega
rotation getRotToPointAxisAt(vector axis, vector target) {
    return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos());
}

// Strength and damping are values used to control how llRotLookAt and llLookAt move, these values are tunable.
float strength = 1.0;
float damping = 1.0;

default {
    state_entry() {
        vector target = <10, 20, 30>; // A vector to look at.

        // These two lines are equivalent, and point the up (Z) axis at the target:
        llRotLookAt(getRotToPointAxisAt(AXIS_UP, target), strength, damping);
        llLookAt(target, strength, damping);

        // This line points the fwd (X) axis at the target:
        llRotLookAt(getRotToPointAxisAt(AXIS_FWD, target), strength, damping);

        // This line points the left (Y) axis at the target:
        llRotLookAt(getRotToPointAxisAt(AXIS_LEFT, target), strength, damping);
    }
}
A strange example to have here since the getRotToPointAxisAt stuff is used for the llRotLookAt function and the llLookAt is only there for a comparison. I'll make use of it anyway. ;-)

Compare with llRotLookAt.


Functions | Dynamics | Rotation
There are 9 comments on this page. [Display comments/form]