Hello. I am making a project in which I created a player node that has as variables the position and the orientation (where it is looking at), both variables are Vector2.
And I also made functional interactuable objects, so when the player can, they interact with the object and a consequence is triggered. But I want to take it to the next step: adding a condition that only when the player faces the object, the interaction can happen.

I made a global variable that records in every frame (delta) where the player is looking at and it works. But I don't know how to apply this variable to the context.
Does anyone know? Thanks!

  • xyz and stranger_anger replied to this.
  • oobiekanoobie Calculate the angle between player's facing vector and the vector that goes from player's position to object's position. If this angle is inside a certain threshold then the player is facing the object. For larger objects you'll probably need to take proximity into account when determining the threshold angle. But we can discuss that once you get the basic system going.

    oobiekanoobie Calculate the angle between player's facing vector and the vector that goes from player's position to object's position. If this angle is inside a certain threshold then the player is facing the object. For larger objects you'll probably need to take proximity into account when determining the threshold angle. But we can discuss that once you get the basic system going.

    oobiekanoobie

    A simple way you could do this is to put a collision area as a child node of your character's scene, in front of where your character is facing. It would rotate along with your character, and you can check for collision with that area when your try to perform an action.

    It won't work if you aren't rotating your character, but you could still move the collision area to be located in the direction your character is looking

    3 months later

    I sort of have an idea. If this works, in a 3d world (this will not help lol), you can add a 3dCamera node inside of another node to detect the facing direction of that node.