Author Topic: Seeing if a player can see another player.  (Read 1439 times)

I'm stumped. Is it possible to see from the server side if a player is in view of another player? I remember mods like this along time ago. Does anyone know how to do this if even possible?

I'm stumped. Is it possible to see from the server side if a player is in view of another player? I remember mods like this along time ago. Does anyone know how to do this if even possible?
It's not a perfect method, but the closest I've ever come is shooting a raycast from the player's eye node at the other player, and then checking to see if it is within the field of view using dot product mathematics. This works fairly well, though. Note that you want to use the eye node and not the head node, or else you'll be able to cheat in 3rd person.

Checking occlusion:

%ray = containerRayCast(%a.getEyePoint(), %b.getEyePoint(), $TypeMasks::FxBrickObjectType);

if (%ray)
  // ... something is in the way
else
  // ... there is a direct line of sight from eye to eye




Checking FOV (assuming %a is trying to look at %b and has a client):

%angle = %a.client.getControlCameraFOV();
%direct = vectorNormalize(vectorSub(%b.getPosition(), %a.getPosition()));
%product = vectorDot(%a.getEyeVector(), %direct);

if (%product >= 1 - (%angle / 360) * 2)
  // ... %b is within %a's viewcone
else
  // ... %b is outside of %a's viewcone




Hull traces might also prove useful.
« Last Edit: April 30, 2014, 02:46:25 AM by Port »

Well, I guess you made it pretty straightforward, then, Port. I was kinda hoping he'd be able to figure out some of it on his own...

-snipy-
Port saving the day once more. Thanks!

Well, I guess you made it pretty straightforward, then, Port. I was kinda hoping he'd be able to figure out some of it on his own...

The point of this post was so I didn't have to figure out how to do it. I could have figured it out with lots of research but this was more effective.

Just one more question, in ports post are %a and %b client objects?
« Last Edit: April 29, 2014, 03:08:28 PM by swatman64 »

Yup, it checks if %a can see %b. (Both are player object ok purt u happy nao)
« Last Edit: April 29, 2014, 03:28:39 PM by Ipquarx »

Just one more question, in ports post are %a and %b client objects?

They are objects that inherit from the Player class—they are players or bots.

For anyone who uses this thread please note that

if (%product >= 1 - (%angle / 360) * 2))

Has one to many closing Parentheses. Think before Copy and Pasting mindlessly

For anyone who uses this thread please note that Has one to many closing Parentheses. Think before Copy and Pasting mindlessly

Oh, whoops - took it from my general purpose FOV script and somehow messed it up when converting from embedded return with another expression to a plain check.