Way to check which side of the Player the NPC is on from Players perspective?

Hi. I’m trying to think of a way to check if the NPC is on the left or right side of the Player from Players perspective. This calculation should happen inside the NPC, because this calculation it’s going to affect the NPC itself. The calculation should take place from all camera angles, because the game has a free 3D camera…

Here is examples:
1
2
3
4
5

Surely this is left?

image

Maybe you mean from the camera’s perspective?

At any rate, take a look at ‘dot product’. You can use it to know where one actor is relative to another.

Yes, from players view (camera).

“Dot product” seems to give some pretty weird and large numbers which I don’t understand at all… and the number gets smaller the farther you go from the NPC.

Dot product is between two direction vectors, so the forward vector of the camera and the player or the NPC. It will always give something in the range -1 ( 180 degrees to each other ) to 1 ( both facing the same way ). 0 is right angles.

You can ACOS is to get the angle.

1 Like

This has nothing to do with camera whatsoever. Not the player’s, and the NPC probably does not even have a camera to start with. Unless you want to check which side of the camera’s fwd something is. But you said NPC and Player.


You want to dot normalised directional vectors:

  • in the NPC:

The above would tell the NPC whether the player is on their left or right. Flip it about if you need it to work the other way round:

And this would tell the NPC on which side of the player they are.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.