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. 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!
Thanks,
Methyl
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(
me.getLocalTranslation()).normalizeLocal();
// 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
Thanks!
I dropped it in and worked like a charm.
glad to hear