Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Compass Compass_By_Dan_Medici  

Compass_By_Dan_Medici

Compass By Dan Medici.lsl

Category: Compass
By : Dan Medici
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for Compass_By_Dan_Medici
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Compass_By_Dan_Medici_1.lsl
1
2 // Compass By Dan Medici
3 //Description: This script finds the cardinal direction that an object is currently pointing towards, and sets it in text above the object that the script is in.
4
5 //Edit: Now fixed to work even when avatar is standing still.
6
7 //How to use: Put inside an object either attached to your avatar or on a moving object.
8
9
10
11
12
13 default
14 {
16 {
17 llSetTimerEvent(0.1); // set a timer event for every tenth of a second
18 }
19
20 timer()
21 {
22 string direction; // this is the variable we will set the text with
23 vector vel = llRot2Fwd(llGetRot());// get the current velocity
24 integer x = llRound(vel.x); // round the x value of the velocity and assign it to a new variable
25 integer y = llRound(vel.y); // round the y value of the velocity and assign it to a new variable
26
27
28 //Keep in mind the following when reading the following part of this script: when one travels perfectly east at a speed of 1.0, their velocity is <1.0,0,0>. Therefore, if they were traveling west,
29 //it would be <-1.0,0,0>. If they were traveling north, it would be <0.0,1.0,0.0>. If they were traveling south, it would be <0.0,-1.0,0.0>. We dont deal with the Z value of the velocity at all
30 //because cardinal directions are based on a two-dimensional coordinate plane.
31 if((llAbs(x) > llAbs(y)) && (x > 0)) // if the absolute value of X is greater than Y, then we are traveling mostly east or west. If X is positive, then we are traveling east.
32 {
33 direction="East";
34 }
35 else if((llAbs(x) > llAbs(y)) && (x < 0)) // if the absolute value of X is greater than Y, then we are traveling mostly east or west. If X is negative, then we are traveling west.
36 {
37
38 direction = "West";
39 }
40 else if((llAbs(y) > llAbs(x)) && (y > 0)) // if the absolute value of Y is greater than X, then we are traveling mostly north or south. If Y is positive, then we are traveling north.
41 {
42
43 direction = "North";
44 }
45 else if((llAbs(y) > llAbs(x)) && (y < 0)) // if the absolute value of Y is greater than X, then we are traveling mostly north or south. If Y is negative, then we are traveling south.
46 {
47
48 direction = "South";
49 }
50 else if((llAbs(y) == llAbs(x)) && (x > 0 && y > 0)) // if the absolute value of Y is equal to X, then we are in an intermediate direction. If both X and Y are positive, then we are traveling nort //heast, because EAST is positive on the X axis and north is positive on the Y axis.
51 {
52
53 direction = "Northeast";
54 }
55 else if((llAbs(y) == llAbs(x)) && (x < 0 && y > 0)) // if the absolute value of Y is equal to X, then we are in an intermediate direction. If X is negative and Y is positive, then we are traveling //northwest
56 {
57
58 direction = "Northwest";
59 }
60 else if((llAbs(y) == llAbs(x)) && (x < 0 && y < 0)) // if the absolute value of Y is equal to X, then we are in an intermediate direction. If X is negative and Y is negative, then we are traveling //southwest
61 {
62
63 direction = "Southwest";
64 }
65 else if((llAbs(y) == llAbs(x)) && (x > 0 && y < 0)) // if the absolute value of Y is equal to X, then we are in an intermediate direction. If X is positive and Y is negative, then we are traveling //southeast
66 {
67
68 direction = "Southeast";
69 }
70 else // not moving
71 {
72 direction = "Stationary";
73 }
74 llSetText(direction, <1,1,1>, 1.0); // set text on the object to what direction we are moving in
75 }
76 }
77 // END //

Back to the Best Free Tools in Second Life and OpenSim.