trivis Posted September 17, 2019 Share Posted September 17, 2019 Somehow I thought this would be easy, but I am still struggling with some rotation things (what's new lol). I am building a positioning HUD. This HUD needs to position me an exact distance left or right of a target-avatar. My rotation is not important (as i understood that a HUD cant rotate me after positioning). The id of the target avatar is known by using llSensor. The positioning of the target is, of course important. My question is how can I determine if I am standing somewhere left or right of my target-avatar (I can be standing in front of the or behind it), and after that positioning myself that exact distance left or right of my target? Thanks in advance for your help, Trivis Link to comment Share on other sites More sharing options...
Mollymews Posted September 17, 2019 Share Posted September 17, 2019 have a look at this follower script: http://wiki.secondlife.com/wiki/Follower_script it shows how to calculate the position to move to. In your case, you are the follower, the target avatar is the key of llGetObjectDetails, and offset.y (+ / -) is left or right of the target 1 Link to comment Share on other sites More sharing options...
trivis Posted September 18, 2019 Author Share Posted September 18, 2019 Thank you @Mollymews! This will help for efficiently positioning beside the target avatar! 1 Link to comment Share on other sites More sharing options...
trivis Posted September 18, 2019 Author Share Posted September 18, 2019 Still curious how i can decide if I am standing somewhere left or right of an target avatar. Any idea? Is llVecNorm the solution? Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted September 18, 2019 Share Posted September 18, 2019 (edited) 3 hours ago, trivis said: Still curious how i can decide if I am standing somewhere left or right of an target avatar. Any idea? Is llVecNorm the solution? Things you need: Your position. Your target's position. From there, you can calculate a vector (XYZ direction) from you to your target. (Or the other way around, doesn't really matter.) Then, if you can check one of the axes (X, Y, or Z) to see if it's negative or not. If it is, you're on one side. If it's not, you're on the other. (The specific one you need to use depends a bit on how you've calculated the vector.) I understand this might seem vague, but the actual vector calculation can be done in two (or more) clean lines of code. Read up on llRotBetween and llRot2Euler. I could just post an example script but since it involves a bit more thinking, it's important that you're able to actually understand how to do it. I suggest you just make a whole new script and try to just make it detect which side you're on, rather than try to edit your current script and fit it in there before it works. Showing debug messages for yourself with llOwnerSay or llSetText so you can see what the numbers are actually doing is also a very important skill you should learn if you haven't already. Edited September 18, 2019 by Wulfie Reanimator 1 Link to comment Share on other sites More sharing options...
trivis Posted September 19, 2019 Author Share Posted September 19, 2019 (edited) Thanks Wulfie!, The new script isnt a problem, i am not testing and trying in an existing script :-) I will try to calculate and understand what you wrote where the solution is! But... the rotation of the target avatar is also involved, isnt it? Looks to me that this rotation is just the issue Thanks again, Trivis Edited September 19, 2019 by trivis Link to comment Share on other sites More sharing options...
trivis Posted September 19, 2019 Author Share Posted September 19, 2019 Worked on the problem... it works fine when I use a "point object" which is left or right of a "avatar object". When the avatar object is a real avatar it doesnt work. The script is: default { touch_start(integer total_number) { key id; id = llGetOwner(); // avatar // id = "e9f7952f-2ac4-0cb7-db9d-4f9a61509593"; // object // target avatar vector avPos = llList2Vector(llGetObjectDetails(id,[OBJECT_POS]),0); rotation avRot = llList2Rot(llGetObjectDetails(id,[OBJECT_ROT]),0); // the math vector A = avPos - <0,1,0>*avRot; vector B = avPos + <0,1,0>*avRot; vector C = llGetPos(); vector AB = B - A; vector AC = C - A; float diff = (B.x-A.x)*(C.y-A.y)-(B.y-A.y)*(C.x-A.x); // left or right // diff > 0 left, diff < 0 right, diff == 0 front/back if (diff > 0 ) llOwnerSay("I am on the left"); if (diff < 0 ) llOwnerSay("I am on the right"); } } Is there anyone who is able to pull me out this deep well? Link to comment Share on other sites More sharing options...
Wulfie Reanimator Posted September 19, 2019 Share Posted September 19, 2019 (edited) Well you had quite a different (plain math) approach to it, so you lose me on the diff part. 😂 But you're right, there is one rotational thing you have to consider. Let me explain. Here's an example object, it's actually two cylinders cut in half, left and right. You can also see the region coordinates (XYZ) on my avatar. First, let's figure out which direction my avatar is from the object's center. list data = llGetObjectDetails(target_avatar, [OBJECT_POS, OBJECT_ROT]); vector target_pos = llList2Vector(data, 0); rotation target_rot = llList2Rot(data, 1); // Arrow from the object to my avatar's position. vector direction = llGetPos() - target_pos; You can see that X is negative, which is correct because my avatar is slightly behind the object in region coordinates. Y and Z are positive because I'm on the left and above the object. Wait, that's it? Y is positive when I'm on the left! Almost -- there's a catch. The catch is that everything is done in global coordinates right now. The calculation breaks (or rather, the result doesn't change) if the target object rotates. To fix this, I'll just take the target's rotation into account. (Actually, it's closer to negating the object's rotation.) direction = direction / target_rot; // Or as a single line instead: vector direction = (llGetPos() - target_pos) / target_rot; Why divide? What about multiply? Read the wiki for detailed explanations. (But in simple terms, the object is rotated 90 degrees to the right. I want to rotate the calculated direction 90 degrees back to the left so we're back in global coordinates.)http://wiki.secondlife.com/wiki/Rotation#Combining_Rotations And now I could add some code to check if Y is positive or negative, and do stuff. It will work even if the object was standing up or at any arbitrary angle. Edited September 19, 2019 by Wulfie Reanimator 1 1 Link to comment Share on other sites More sharing options...
trivis Posted September 19, 2019 Author Share Posted September 19, 2019 Wow that is amazing @Wulfie Reanimator!!!!! You've put so much effort in answering my question. You're a hero! Will program this later today, if you dont mind, have to do some work first :-) T H A N K S Link to comment Share on other sites More sharing options...
trivis Posted September 19, 2019 Author Share Posted September 19, 2019 It works like a charm, @Wulfie Reanimator! Thanks again for your great educational effort :-) Very much appreciated. Kind regards, Triv 2 Link to comment Share on other sites More sharing options...
Recommended Posts
Please take a moment to consider if this thread is worth bumping.
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now