TheSmokie 242 Posted June 18, 2020 Share Posted June 18, 2020 Hello, i am trying to figure out how to get a facing target from the vector3, the angle, and targets vector3. We have the following data: - Our Vector3 Position (X, Y, Z) (100, 100, 0) - Our Current Facing Angle (Pitch, Yaw) (90, 180) - Targets Vector3 Position (X, Y, Z) (200, 200, 0) How do we calculate the Angle (Pitch, Yaw) that I would need to reach to be facing our target. I just need the math function to take the input and output the info i need. the rest i can do. -Smokie Link to comment Share on other sites More sharing options...
reapler 154 Posted June 18, 2020 Share Posted June 18, 2020 I believe this should work: /// <summary> /// Used to get the facing from two positions based on the origin rotation. /// </summary> /// <param name="from">The 1. position.</param> /// <param name="to">The 2. position.</param> /// <param name="originRotation">The origin rotation.</param> /// <returns>Negative radian on the right; positive on the left.</returns> public float FacingCenter(WoWPoint from, WoWPoint to, float originRotation) { var face = NormalizeRadian(Atan2Rotation(from, to) - originRotation); if (face < Math.PI) return -face; return NormalizeRadian(originRotation-Atan2Rotation(from, to)); } /// <summary> /// Used to normalize the input radian. /// </summary> /// <param name="radian">The radians to normalize.</param> public float NormalizeRadian(float radian) { if (radian < 0.0) return (float) (-(- radian % (2.0 * Math.PI)) + 2.0 * Math.PI); return radian % 6.283185f; } /// <summary> /// Used to calculate atan2 of to positions. /// </summary> /// <param name="from">Position 1.</param> /// <param name="to">Position 2.</param> /// <param name="addRadian">Radians to add.</param> /// <returns></returns> public static float Atan2Rotation(WoWPoint from, WoWPoint to, float addRadian = 0) { return (float) Math.Atan2(to.Y - from.Y, to.X - from.X) + addRadian; } /// <summary> /// Used to calculate new position by parameter. /// </summary> /// <param name="from">The position to calculate from.</param> /// <param name="rotation">The rotation of the object in radians.</param> /// <param name="radius">The radius to add.</param> /// <returns></returns> public static WoWPoint CalculateNewPosition(WoWPoint from, float rotation, float radius) { return new WoWPoint(Math.Sin(rotation) * radius + from.X, Math.Cos(rotation) * radius + from.Y, from.Z); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now