Jump to content

Is Avatar Facing Target?


Ruthven Ravenhurst
 Share

You are about to reply to a thread that has been inactive for 2374 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello! Old SL user, but was away for a long time! I hadn't used SL since around the time that shadows were made more dynamic, and came back to many wonderful changes! I'm working on a script for wands, and for the particle effect to look right for some spells, the avatar needs to be facing its target. I'm sure there's some way of doing that by checking the rotation of the avatar to the relativity of the target, but I don't know the logic to make that happen. Of course I'm sure that wouldn't work if the avatar is sitting, say on a pose ball, and then of course animations cause a whole different problem with that. My goal in developing the wand, is to also create an animation, possibly for each spell. Animations aside, assuming the pose balls used are for dueling, in which case, I would assume would be facing each other, I would also want the script to check if the avatar is sitting, and if not, it would check to make sure it is facing the target. Sorry to ramble, I've been up all day and had too much coffee.

Link to comment
Share on other sites

Welcome back, Ruthven!

This is the calculation you ask for:

		key id;//target's uuid		vector vStart = llGetPos()+<1.0,0.0,0.0>*llGetRot();//my positive x axis		vector vEnd = llList2Vector(llGetObjectDetails(id,[OBJECT_POS]),0);		rotation rot = llRotBetween(vStart,vEnd);//the angle between my positive x axis and the target		llOwnerSay((string)rot);		vector vec = llRot2Euler(rot)*RAD_TO_DEG;		llOwnerSay((string)vec.x); //degrees between the direction in which I'm facing and target position

However, if vec.x is not 0.0 -- that is, you're not looking straight at your target -- you don't know whether you're going to hit  it or not.   That depends on distance between you and the target, and is not easy to calculate.

So I would suggest using llCastRay instead.  

If you decide the maximum range for your spell is 20.0 metres, you would do a ray-cast between llGetPos() and llGetPos()+<20.0,0.0,0.0>*llGetRot() (20 metres on your positive x axis) and see what, if anything, you hit.

That's how I would do it, anyway.

Link to comment
Share on other sites

You can get a rough idea of which way an avatar is facing if you detect it with a sensor and then ask about llDetectedRot(0).  That's really only a rough indication, because it doesn't know about any apparent rotations that may be due to animations -- all of which are client-side.

You can tell whether the avatar is sitting by using its UUID and asking for llGetAgentInfo and checking AGENT_SITTING

Link to comment
Share on other sites

vector avPos = llGetPos();rotation avRot = llGetRot(); // some of the previous posts deal with the avatar rotation which is worth some considerationsvector targetPos; // find this with sensor or whatever// Now compute two unit vectorsvector facing = llRot2Fwd( avRot);vector target = llVecNorm( targetPos - avPos);// finaly compute the dot product of both vectorsfloat dp = facing*target; // ( this is the same as cosinus to the angle between the vectors!! look it up:) )if ( dp == 1.00 ) // you are facing target exactly// since vi operate in floats and want something not perfct to be accepted, use something smaller than one// like:if ( dp >= 0.95 ) // you are facing target

:smileysurprised::):smileyvery-happy:

Link to comment
Share on other sites

Thanks! I'm not worried too much about an exact facing, I just don't want the particles coming out and moving in too much of a curve, or back through my avatar,  if my avatar is facing to much away from the target (whether it be an object or an avatar). I didn't know about the llCastRay function though, and can see where it might be usefull for some other ideas that I have.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2374 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...