## Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

# For nonphysical movers: Avatar unit direction and rotation functions

Huns Valen
Don't PM me here.
Join date: 3 May 2003
Posts: 2,749
03-14-2004 23:06
These functions can be used to figure out a point directly in front of an avatar, i.e. lined up with the direction the avatar is facing, as well as how to rotate an object so that it is looking at the avatar. Normally you can use llLookAt(), but my project was for a nonphysical mover, so that wouldn't work for me.

What you can do with this is move your object so that it's directly in front of an avatar, and then have it look at the avatar.

CODE
`// Purpose: Determine a point in front of an avatar, in the direction the//          avatar is facing.// Arguments: pos, the position of an avatar. rot, the avatar's rotation.// Returns: A vector that is in front of the avatar, two meters away, and// 1.5 meters above its center.vector getAgentUnitDir(vector pos, rotation rot) {    // Figure out where the agent is and where they're looking    vector agentUnitDir;    float dist = llVecDist(llGetPos(), pos);        // Calculate the intruder's unit direction    // This is a point one meter in front of the intruder's face    // We double this and then add some height    agentUnitDir = pos + (2 * llRot2Fwd(rot));    agentUnitDir.z += 1.5;    return agentUnitDir;}// Purpose: Figure out what rotation will cause an object to "look"//          at a speicific position.// Arguments: agent, the position of an avatar. me, your position.// Returns: A rotation which, if applied to an object, will cause it to//          "look at" the location passed in the agent variable.rotation getRotToAgent(vector agent, vector me) {        // Figure out vector between myself and the intruder        vector normal = (agent - me) / llVecDist(agent, me);            // Convert (x, y) on unit circle into degrees        float deg = -(llAtan2(normal.y, normal.x) * RAD_TO_DEG);                        // Whack degrees if (x, y) were in quadrant 2 or 3 of unit circle        // (we want {0 - 360}, not {-180 - 180})        if(deg<0) deg=360-llFabs(deg);        // Set our rotation to the default X and Y        // The Z is the only thing impacted by the intruder, since we        // Want to remain upright.        // You may have to change this for your object.        return llEuler2Rot(<-PI, 0, DEG_TO_RAD * (deg - 90)>);}`

I've added some comments to the top of each function to explain what it does.
_____________________
Inferniel Solvang
Registered User
Join date: 31 Jan 2005
Posts: 47
help
03-31-2005 21:14
i was looking for this exact function...but how do i implement it
Coos Yellowknife
Registered User
Join date: 25 Jul 2004
Posts: 27
I beleve this is what I am sortoflooking for also
04-04-2005 18:19
I am trying to get a way that I can rez an object infront of the avitar with the attachment. I have read in wiki that if it is attached it returns the avie's pos and rotation. I want to rez an object up to the 10 meter limit basicly in front of the avitar. The objects rotaion is not that important (I would like i to rez as built basicly)

I would like to know if the variables passed to these functions are the avie's Pos and rotation. I am guessing they are. Any other help with this woud be great. Thanks!
Cartman Ludd
I'm with stupid ---->
Join date: 25 Mar 2005
Posts: 11
04-05-2005 21:29
What exactly is the point for this script?
_____________________
Siggy's are stupid. 'Hey, look! Its that really random signature that I have had to read for the last 6 weeks, because that darn person is to defective to change it!' If this is you, I think we should get our freakin' panzerfrausts and blow every signature on this forum to kingdom come. Thank you for ignoring my signature, and if you went through painstaking process of reading it, then either you have to much time on your hands, or you have the I.Q of the slug.
Tiger Crossing
The Prim Maker
Join date: 18 Aug 2003
Posts: 1,560
04-06-2005 12:24
Huns... "Intruder"?
_____________________
~ Tiger Crossing
~ (Nonsanity)