# How do I determine if one object is in front of another?

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

## Recommended Posts

Given the position and rotation of an object, how do I determine if another object is in front of it?

Also, how would I determine if the other object is within a given angle of the first object's forward axis?

I guess those are both the same question, in that in the first case the angle would be 90°, though I suspect that calculation can be simplified.

##### Share on other sites

Are you concerned with occlusion? or is this just about the location of the "in front" object's origin?

If the former, you'll need to raycast. The latter is some solid geometry that seems as if it should be pretty simple, but I'm too sleepy to be a reliable source. Off the top of my head, I'm thinking maybe

the llRotBetween

• the first object's forward axis (llRot2Fwd maybe) and
• the unit vector in the direction of the possibly-in-front object (maybe llVecNorm of the difference in position vectors).

but like I said, I'm pretty sleepy, so sorry if it's totally wrong or crazily overcomplicated.

• 1
##### Share on other sites

`float angle = llAcos(<1,0,0> * target - llGetPos)`

Or

```rotation rot = llRotBetween(<1,0,0>, target - llGetPos);
float angle = llAngleBetween(ZERO_ROTATION, rot);```

Edited by Wulfie Reanimator
• 1
• 1
##### Share on other sites

Blimey! That was painless! Many thanks!

And yeah, occlusion and llCastRay did come into it, but that part was easy, seein' as how there's no angles involved.

(By the way, you want ZERO_ROTATION in that llAngleBetween call, not ZERO_VECTOR.)

• 1