Don't click here unless you want to be banned.

LSL Wiki : llLookAt

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org
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.

llLookAt works on attachments also but it's rotation is relative to the avatar's that it is attached to.

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.


This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Dynamics | Rotation
Comments [Hide comments/form]
Anyone know how I can re-create this using raw math (With llSetRot and such) so I don't have to deal with power and damping values on a non-physics object?
-- SchitsoMonkey (2006-01-31 12:02:16)
Use llSetRot instead of llRotLookAt, in the included code snippet.
-- SchizzySapeur (2006-02-24 05:34:59)
Will this function work if I put it in a child prim?
-- AlkenanK (2006-03-01 10:43:12)
If you use llSetLocalRot instead of llRotLookAt, yes - I think :-)
-- ChristopherOmega (2006-03-01 10:53:55)
I mean I need a function or something that takes the vector that i want to look at, and returns the rotation required to be pointing an axis (doesn't matter at this point) towards that vector.
-- SchitsoMonkey (2006-03-01 16:21:09)
I see the math is too scary for everyone! >_> I can't seem to find anything about it that would help me...
-- SchitsoMonkey (2006-03-12 12:51:51)
llRotBetween is what you might be looking for. It gets rotation needed for vector a to vector b.
-- KairaOverdrive (2006-04-10 03:06:15)
Look at the script above.
Snippet:
rotation getRotToPointAxisAt(vector axis, vector target) {
return llGetRot() * llRotBetween(axis * llGetRot(), target - llGetPos());
}
-- KairaOverdrive (2006-04-10 03:07:48)
If you want quick llLookAt's then I suggest using a strength of llGetMass(), as this causes damping to behave like the tau value in calls to llMoveToTarget (ie lower damping means faster look ats).

I'm not sure what the current (at time of posting) reccommended values were intended for, but I find them to be very poor in practise, especially for a physical object that may have avatars (or variable numbers of avatars) sitting on them, as behaviour became inconsistent for me. Whereas if you use the full mass for strength and a constant for damping it behaves much more dependably.

In fact I don't really know why they have two values to determine the speed, when really one tau value would do. If you then needed to take into account mass you could.
-- HaravikkMistral (2006-06-22 12:55:05)
The remark about no longer working on non-physical objects as of 16 March 2007 is unclear about whether that's a good thing or bad thing. "thanks LL" could be literal or sarcastic. (Oh, the joys of internet communcation.)

So is it good or bad, and if bad, is it expected to be fixed?
-- MarsConsult (2007-04-14 07:57:47)
I've just removed the remark. llLookAt works fine with non-physical objects. If it stopped working with non-physical objects, that would be a bad thing. (One would hope that would be obvious, but maybe not...)
-- GaiusGoodliffe (2007-04-23 04:23:16)
Attach a comment to this page: