Im working on a wolf which should turn its head towards the location of the ThreatActor. However, I cant seem to find a solution to getting the angle from the front of the wolf towards the player. My current solution works, but only in the positive degrees. This makes the wolf head always bend to the right, even when I am walking on the left side of the wolf. My question is: How can I find the angle (from the front of the wolf) to the ThreatActor somewhere around it based on the location of the wolf and the ThreatActor?
You’re probably using the dot product & acos method to get the angle between two vectors. The acos function never returns a negative value so you’d need to negate the result if one of the inputted vectors have negative components.
Or better, instead of comparing the enemy’s forward vector with the vector pointing at the player, you can simply use the Find Look at Rotation node to get what the rotation of the enemy should be in order to be looking at the player. Note that the result will be the world rotation and not a local rotation.
Here you go. This is the relative rotation. Set the Z value when setting the relative rotation. If you want absolute rotation, use the Z directly from the FindLookAtRotation node.
Source Actor is the wolf. Target Actor is the ThreatActor
Note that I made this work on the XY plane. If you want arbitrary rotations, that can be done, but it’s not a simple angle. You can use the FindLook at Rotation.