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
Useful Subroutines integer_left_or_rightvector_baselin  

integer_left_or_rightvector_baselin

integer_left_or_rightvector_baselin

Category: Useful Subroutines
By : LSL Wiki
Created: 2010-02-01 Edited: 2010-02-01
Worlds: Second Life

the Zip file

Download all files for integer_left_or_rightvector_baselin
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. integer_left_or_rightvector_baselin_1.lsl
1 integer left_or_right(vector baseline, vector target)
2 {
3 //Returns whether the target vector is to the left or right of the baseline vector
4 //returns 0
5 //straight ahead = 0 (baseline == target)
6 //left = 1
7 //right = -1
8 //directly behind = 2
9 if(llVecNorm(baseline) == llVecNorm(target))
10 {
11 return 0;
12 }
13 if(llVecNorm(baseline) == llVecNorm(target) * -1)
14 {
15 return 2;
16 }
17 rotation rot_between = llRotBetween(baseline,target);
18 vector euler_rot = llRot2Euler(rot_between);
19 float z_rot = euler_rot.z;
20 if(z_rot > 0)
21 {
22 return 1;
23 }
24 else
25 {
26 return -1;
27 }
28 }
29
30 //Example uses
31 default
32 {
34 {
35 llOwnerSay("Left or Right example");
36 }
37
38 touch_start(integer total_number)
39 {
40 llOwnerSay("Detecting Avatar");
41 llSensor("","",AGENT,60,PI);
42 }
43 sensor(integer num)
44 {
45
46 //Is the detected avatar to the left or the right of this object's current heading
47 integer target_L_or_R = left_or_right(llRot2Fwd(llGetRot()),llDetectedPos(0) - llGetPos());
48 if(target_L_or_R == 1)
49 {
50 llOwnerSay("Avatar is to the left of me");
51 }
52 else
53 {
54 llOwnerSay("Avatar is to my right");
55 }
56
57
58 //In relation to the object's heading, is the detected avatar facing to the left or right?
59 integer moving_L_or_R = left_or_right(llRot2Fwd(llGetRot()),llRot2Fwd(llDetectedRot(0)));
60 if(moving_L_or_R == 1)
61 {
62 llOwnerSay("Avatar is facing to my left");
63 }
64 else
65 {
66 llOwnerSay("Avatar is facing to my right");
67 }
68 }
69 }

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