Checking if a node is facing another node

Hey guys,

I'm currently coding my player's attack action. Essentially, when the user clicks the mouse button I would like to check if my player is facing the other player he is attacking. It would look awkward if the model isn't facing what he is attacking.  :stuck_out_tongue: So, how would I go about this?

I attempted to work out my problem on paper and I ended up using the Law of Cosines/Sines, which seems a too computationally heavy. I'm still befuddled by JME's measurement of angle rotations so I wouldn't know how to implement my own method if I wanted to. I'm sure there is a simple way doing this, I'm just too lost figure it out.  :roll:

I'd appreciate any help given!



You can use something like that, thats the method i use to see if player is in the enemys field of view

'me' refers to the player node, 'target' is the target to check.

    private boolean isVisible() {
        // get the direction from us to the player
        Vector3f direction = target.getLocalTranslation().subtract(
        // get the difference between the Enemy's heading direction and the direction to the player
        Vector3f difference = me.getLocalRotation().getRotationColumn(2).subtract(direction);
        if (difference.length() > 0.5f) {
            // 2   == 180


I dropped it in and worked like a charm.  :smiley:

glad to hear :slight_smile: