Hello.
I am working with a 3d plugin and want to do doom style graphics were enemies are sprites. I am stuck trying to figure out how to make the correct animation play depending on what direction an enemy is facing relative to the player though.
I have 8 animations named something like "action0) were "action" is what the animation is of the character doing (idle,walking, ect) and the number at the end is the direction.
I first looked at finding the difference of angles between the camera and enemy but quickly found out that would not return the correct angle of facing.
any help would be appreciated
Thanks
UPDATE: So after some extra digging I know I need a dot product. This is the equation as I understand it ( (a1,a2)•(b1,b2) = a1b1 + a2b2 )
but the test I set up does not seem to be working (is not returning a number between 1 and -1 ). no doubt its staring me in the face but I have brick walled. any input?
UPDATE 2: so I think I solved it
the above math was correct in that it was indeed giving a positive or negative value related to the facing of the enemy relative to the player. it just was not in the range of 1,-1
I seem to have gotten it inside that range though regardless of the distance by taking the distance of the player and enemy and multiplying it by 3. and then dividing the dot product by this number. it seems to be working so I will stop with this result.
as you can see in the two screenshots in the image the dot product is now inside the 1,-1 range regardless of the distance.
UPDATE 3: seem to have the solution implemented.
no doubt there is a cleaner way of doing this but my solution is to get the dot product for both the front and side. this way I can see how forward and how sideways facing the entity is. I then compare the front dot value to see if it is front or rear facing and then compare the side dot to see what side is facing.
Video of the effect in action. I am not sure if it's perfect but it seems ok to me.