I'm working on a VR game in Unreal Engine 4 using Blueprints.
I want to calculate the (yaw) angle the user needs to turn his/her gun (whose direction is determined via the position of the motion controllers) in order to be pointing towards the target.
I figure this might be the way to do it:
- Subtract the location of the target from the location of the gun
- Get the yaw component of that as a vector pointing from the gun as origin
- Subtract the current yaw of the gun direction from that yaw component to get the yaw angle the user needs to turn to get to the target
Except I'm not quite sure how to execute that. I've been experimenting (as seen in the screenshot below), but not doing the correct operations. Any thoughts?
Thanks!
target location - firearm location
then normalize. Find the yaw of that normalized value to createyaw of target direction
Then, findyaw of the firearm's forward vector
. Then, subtract againyaw of target direction - yaw of firearm's forward vector
to produceyaw delta from firearm's forward to target direction
– Eph