What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Getting Degree's of where you are to a players Radius

swiny

New Member
Joined
Dec 19, 2010
Messages
517
Reaction score
73
Hey Guys,

i have a really technical maths question. and due the fact i hate maths. im asking you guys lol.

What im trying to get is,

my Degree's or radian of where my location is, compared to a other person.

pic.webp

Basiclly its the "guts" out of IsBehind, exept a bool is a output.

i have asked Apoc if there is a function like this in Honorbuddy,
unfortantly there isnt.

ANY help!?
 
I think Singular has some code for this. To check if target is within a cone in front of you.

btw could you contact me on skype/irc when you get the chance?
 
Singular
return otherUnits.Count(u => target.IsSafelyFacing(u, 90f) && u.Location.Distance(targetLoc) <= distance);

Not what im after :(
 
I really don't understand the question in its current form but I think you want to get the angle between the local player and a target relative to the local player, in which case you'll probably need to use trig. If you're ignoring the z-axis you can simply use the atan2 function (Math.Atan2 Method (System)). Give it the 2D vector between the two points and it will deal with quadrant correction for you and return the result in radians. Be sure to divide by 180 and multiply by PI to get the answer in degrees, and also remember the origin of rotation will be east and north will be considered 90 degrees. Same principle if you want to find the angle between the two relative to the target, in which case you need just need to change the order of the vectors (V1 - V2 vs V2 - V1.)

If you want to take into account the z-axis things get more complicated and I would suggest the above link on 3d maths or googling for further info.
 
Last edited:
Got it that arvo,

This is for any one that might need it later

Code:
        public static double GetDegree
        {
            get
            {
                double d = Math.Atan2((Target.Y - Me.Y), (Target.X - Me.X));

                double r = d - Target.Rotation; 	  // substracting object rotation from absolute rotation
                if (r < 0)
                    r += (Math.PI * 2);

                return WoWMathHelper.RadiansToDegrees((float)r);
            }            
        }
 
Wow! Now that is not what I would have come up with :p
 
whoa... I love math but that made my head swim... of course, it is 5:30 am here right now and I'm just drinking my first cup of coffee... still way too much blood in my caffeine supply.

Good job on finding the answer though!
 
whoa... I love math but that made my head swim... of course, it is 5:30 am here right now and I'm just drinking my first cup of coffee... still way too much blood in my caffeine supply.

Good job on finding the answer though!

Too much blood in your caffeine? o.O
 
Its like having some hamburger in your spit from the local fast food joint...
 
If you think this is complicated math, you really really need to relearn your trigonometry or vector dot products. :P
The problem is extremely simple to solve using vectors:
Dot product - Wikipedia, the free encyclopedia

61b787a32065fdf49cc7afe06fc27494.png

Basically create two vectors, a mob->player vector and a mob direction vector, and use that formula right there to get the angle between the two vectors.
Angle_between_vectors.png

This is exactly how HB does it:
Code:
Vector3 meToTarget = target - me;
meToTarget.Z = 0;
Vector3 myDir = new Vector3((float)Math.Cos(myFacingRadians), (float)Math.Sin(myFacingRadians), 0);

float dot = Vector3.Dot(ref myDir, ref meToTarget);
float angle = (float)Math.Acos(Clamp(dot / (meToTarget.Magnitude * myDir.Magnitude), -1, 1));
 
Back
Top