Unofficial LSL Reference

[[functions:llapplyrotationalimpulse]]


Unofficial LSL reference

User Tools

Login

You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.

Login

Forgotten your password? Get a new one: Set new password

Function: llApplyRotationalImpulse

llApplyRotationalImpulse(vector impulse, integer local)

Apply an instant change to the angular momentum of a physical object. It has no effect on non-physical objects or on attachments.

Parameters

impulse

A vector specifying the impulse to apply, which will add to the object's current angular momentum. The vector's direction indicates the impulse's axis and its length indicates the magnitude. The units of the angular impulse vector seem to be lindograms·m²/s. Like in the real world, the effect on the angular velocity depends not only on the mass of the object, but also on its shape, as it's the product of moment of inertia (which itself depends on the shape of the object) and angular velocity.

local

Boolean value indicating whether the impulse axis' coordinates are local to the root prim (if TRUE) or in sim coordinates (if FALSE).

When TRUE, the impulse axis' coordinates are local to the root prim. For example, if impulse is <1, 0, 0> and the X axis of the root prim is looking northwest, then the impulse will have its axis oriented in the northwest direction, aligned with the root prim's X axis.

When FALSE, the vector specifies sim coordinates, where positive X is east, positive Y is north, positive Z is up, and vice versa for negative; for example, if impulse is <-1, 0, 0>, the rotational impulse will have its axis pointing west, no matter how the root prim is oriented.

Notes

  • The maximum angular velocity of an object seems to be about 127 rad/s (about 1212 rpm). Note, however, that llGetOmega will not return a value with a magnitude greater than 62.8 rad/s (about 599.7 rpm).

Short examples

// Assuming a 1x1x1 cube with no gravity and no initial angular velocity,
// the following line will make it spin at an initial angular velocity of 0.6 rad/s
// over its local Z axis:
llApplyRotationalImpulse(<0, 0, 1>, TRUE);
// 0.6 rad/s is derived from the moment of inertia of a cube spinning over its
// axis (m*l^2/6, where l is the length of the side) and the impulse applied.
// The mass of such a cube is 10 lindograms. Measurement with llGetOmega
// indicates that it works this way.

Complete examples

This example verifies the physical accuracy of llApplyRotationalImpulse on an undeformed box of any dimensions. Moment of inertia varies with shape, so most deformations affect the results.

llApplyRotationalImpulse-test.lsl
float IMPULSE = 1.31; // change this value to any value to test

default
{
    touch_start(integer n)
    {
        // Disable gravity, enable physics, wait for the setting to take effect
        llSetPhysicsMaterial(GRAVITY_MULTIPLIER, 0, 0, 0, 0);
        llSetStatus(STATUS_PHYSICS, TRUE);
        llSleep(0.5);

        // Begin the test
        llApplyRotationalImpulse(<0, 0, IMPULSE>, TRUE);
        llSleep(0.03); // let a simulator frame pass

        // NOTE: Rotational friction is applied almost instantly, meaning the
        // returned value will be less than the theoretical one most of the
        // times. Sometimes we're lucky and get the actual value.
        vector omega = llGetOmega();

        // Disable physics again, return to zero rotation.
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetRot(<0, 0, 0, 1>);

        // Calculate and report results.
        vector size = llGetScale();
        // Predicted omega is impulse divided by moment of inertia.
        // Moment of inertia of a box rotating on its z axis is m*(size.x²+size.y²)/12.
        float predicted = IMPULSE/(llGetMass()*(size.x*size.x+size.y*size.y)/12);
        llSay(0, "Theoretical omega: " + (string)predicted
                   + ", actual omega: " + (string)omega.z
                   + ", difference:" + (string)(predicted - omega.z)
             );
    }
}

See also