sowelu 1 Posted October 4, 2017 Share Posted October 4, 2017 Hello, how to get any info about character's rotation? (need to get an angle). Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/ Share on other sites More sharing options...
Droidz 2738 Posted October 5, 2017 Share Posted October 5, 2017 https://github.com/acidburn974/lazybot/blob/99c2c15e28bfc07cb9726192c4d083c884abe327/LazyBot evolution/LazyLib/Manager/Wow/Location.cs#L221-L249 (lines 227 and/or 239) Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33156 Share on other sites More sharing options...
reapler 154 Posted October 5, 2017 Share Posted October 5, 2017 Hello, this should work: private static double ActualRotation(double value, double min, double max) { if (value < min) return min; return value > max ? max : value; } public static double CalculateFacingCenter(Vector3 source, float playerRotation, Vector3 destination) { Vector3 v2 = destination - source; v2.Z = 0.0f; Vector3 v1 = new Vector3((float) Math.Cos(playerRotation), (float) Math.Sin(playerRotation), 0.0f); return Math.Acos(ActualRotation(Vector3.Dot(ref v1, ref v2) / (v2.Magnitude() * (double) v1.Magnitude()), -1.0, 1.0)); } And additional snippets which could help you: /// <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 Vector3 CalculatePosition(Vector3 from, float rotation, float radius) { return new Vector3(System.Math.Sin(rotation) * radius + from.X, System.Math.Cos(rotation) * radius + from.Y, from.Z); } /// <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 float Atan2Rotation(Vector3 from, Vector3 to, float addRadian = 0) { return (float) System.Math.Atan2(to.Y - from.Y, to.X - from.X) + addRadian; } /// <summary> /// Used to face to the desired position. /// </summary> /// <param name="to">The position to face.</param> /// <param name="addRadian">Radians to add from the position.</param> public static void Face(Vector3 to, float addRadian = 0) { wManager.Wow.Helpers.ClickToMove.CGPlayer_C__ClickToMove(0, 0, 0, wManager.Wow.ObjectManager.ObjectManager.Me.Guid, 2, (float)System.Math.Atan2(to.Y - wManager.Wow.ObjectManager.ObjectManager.Me.Position.Y, to.X - wManager.Wow.ObjectManager.ObjectManager.Me.Position.X)+addRadian); } Usage for second block(i guess first one should be understandable) //turn 180° Face(ObjectManager.Target.Position, (float)System.Math.PI); //turn left Face(ObjectManager.Target.Position, 1.53589f);//88° = 1.53589 rad //turn right Face(ObjectManager.Target.Position, -1.53589f);//88° = 1.53589 rad Matenia and arkhan 2 Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33158 Share on other sites More sharing options...
sowelu 1 Posted October 5, 2017 Author Share Posted October 5, 2017 Unbelievable, thanks! Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33167 Share on other sites More sharing options...
sowelu 1 Posted October 8, 2017 Author Share Posted October 8, 2017 Shiet, I'm so weak in math, can you help me please adapt it to get an angle value between -180 to 180 depend on where target is. (-90 left, 0 facing, 90 right) Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33297 Share on other sites More sharing options...
reapler 154 Posted October 9, 2017 Share Posted October 9, 2017 This should finally do the desired work while the other method was just for calculating :) /// <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(Vector3 from, Vector3 to, float originRotation) { var face = NormalizeRadian(Atan2Rotation(from, to) - originRotation); if (face < System.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 * System.Math.PI)) + 2.0 * System.Math.PI); return radian % 6.283185f; } /// <summary> /// Used to calculate atan2 of to positions. /// </summary> /// <param name="from">The 1. position.</param> /// <param name="to">The 2. position.</param> /// <param name="addRadian">Radians to add.</param> /// <returns></returns> public float Atan2Rotation(Vector3 from, Vector3 to, float addRadian = 0) { return (float) System.Math.Atan2(to.Y - from.Y, to.X - from.X) + addRadian; } Usage: var rot = FacingCenter(ObjectManager.Me.Position, ObjectManager.Target.Position, ObjectManager.Me.Rotation); if (rot < 0) Logging.Write("Facing to right: "+rot); Logging.Write("Facing to left: "+rot); sowelu and Matenia 1 1 Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33308 Share on other sites More sharing options...
sowelu 1 Posted October 9, 2017 Author Share Posted October 9, 2017 Look what I have when rotate character while moving. Any idea how can it be fixed? Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33311 Share on other sites More sharing options...
reapler 154 Posted October 9, 2017 Share Posted October 9, 2017 I assume you are using the "Rotation" property from your playerclass to change the rotation, but this should be only used to get rotation values. This behavior occures because you are only changing your client-side rotation but not your actual rotation on the server. It can be fixed either using the mentioned "Face();" method in my previous posts (dunno if it works on vanilla) or by a nudge turn via keypress / lua (http://wowwiki.wikia.com/wiki/API_TurnLeftStart & http://wowwiki.wikia.com/wiki/API_TurnLeftStop) Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33312 Share on other sites More sharing options...
sowelu 1 Posted October 9, 2017 Author Share Posted October 9, 2017 Dont work in my code, so , is there no way to inplement swift rotation from code ? Key rotation too slow. Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33319 Share on other sites More sharing options...
sowelu 1 Posted October 9, 2017 Author Share Posted October 9, 2017 Some kind of sucsess on BC Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33322 Share on other sites More sharing options...
sowelu 1 Posted October 9, 2017 Author Share Posted October 9, 2017 Also, how can I get time between framerates or do something every framerate Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33323 Share on other sites More sharing options...
reapler 154 Posted October 9, 2017 Share Posted October 9, 2017 16 minutes ago, sowelu said: Dont work in my code, so , is there no way to inplement swift rotation from code ? Key rotation too slow. I forgot to illustrate the other method more detailed. You can actually write your radians to rotation property at the player class (like you did), but after the write it is needed to update the rotation via a nudge: ObjectManager.Me.Rotation = 1.1f; //or use robotmanager's keyboard class Lua.LuaDoString("TurnLeftStart();"); Lua.LuaDoString("TurnLeftStop();"); Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33324 Share on other sites More sharing options...
sowelu 1 Posted October 9, 2017 Author Share Posted October 9, 2017 Finally i got it Link to comment https://wrobot.eu/forums/topic/7284-how-to-get-angle-or-rotation-info/#findComment-33326 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