User:Toy Wylie/RLV Documentation/setrot

From Second Life Wiki
< User:Toy Wylie‎ | RLV Documentation
Revision as of 20:32, 10 April 2012 by Felis Darwin (talk | contribs) (Added an example on how to turn a direction vector into an angle. Sorry to edit your page but you have the best documentation on this)
Jump to navigation Jump to search


@setrot

Type

General

Implemented

Implemented since RLV version 1.17

Usage

@setrot:<angle>=force

Purpose

Rotates the user's avatar to face the angle given in radians. An angle of 0.0 means "Face North". Keep in mind that an avatar will only rotate if the difference is big enough from the current rotation. The threshold is around 6° to 10°.


See Also

Example

<lsl>default

{

   touch_start(integer num)
   {
       if(llDetectedKey(0)==llGetOwner())
       {
           float angle=llFrand(TWO_PI);
           llOwnerSay("@setrot:"+(string) angle+"=force");
           llOwnerSay("You are now facing "+(string) ((integer) (angle*RAD_TO_DEG))+"° from the north.");
       }
   }

}</lsl>

Direction Vector to Angle

It's very easy to turn a direction vector (such as the distance between two points) into an angle that can be used with this command: <lsl>default {

   touch_start(integer num)
   {
       //== When the owner touches us, make them face us
       if(llDetectedKey(0)==llGetOwner())
       {
           vector diff=llGetPos() - llDetectedPos(0);
           float angle=llAtan2(diff.x, diff.y); // Note that this is X first, then Y, contrary to what documentation would make you think you should use
           llOwnerSay("@setrot:"+(string) angle+"=force");
           llOwnerSay("You are now facing "+(string) ((integer) (angle*RAD_TO_DEG))+"° from the north.");
       }
   }
}</lsl>