User Tag List

Results 1 to 8 of 8

Thread: Vector angle math

  1. #1
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    tompa's Avatar
    Join Date
    Nov 2011
    Location
    Uppsala, Sweden
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Vector angle math

    Hi guys

    I need a way of measuring if my vector-angle is positive or negative.




    I did the Dot product process and used inverse cosine to gain my angle and it works (actually).
    Problem is that it doesn't tell me if I'm on the right or left side of the vector, only that it's X degrees until I'm looking at it.


    It's a longshot asking this but maybe some of you know about it.


    Thanks,
    Tompa


    --edit--
    the pic shows a point system not vector, but it shows my "issue" and the point system give me the same problem.

  2. #2
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,393
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    AngleDiff = (( AngleCurrent - AngleTarget +540) mod 360)-180

    The sign of the result will tell you which side you're on. Obviously you can get the angle of a vector using ATan2().

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    tompa's Avatar
    Join Date
    Nov 2011
    Location
    Uppsala, Sweden
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow, you can grab the angle between two 3D-vectors using Atan2()?? please tell how. ^^

    This is the only Atan2 angle formula I know:
    A = Source position
    B = Target position
    C = Angle


    C = ATan2(A.y - B.y, B.x - A.x)


    I've been doing this so far:
    A = Camera position vector
    B = Farclip plane position vector
    C = Enemy position vector
    D = scalar angle


    D = aCos(dot((B - A), (C - B)) / (sqr( A pow 2) * sqr( C pow 2)))


    now dot() isn't a function in MMF but I'm sure you see what I mean.


    --------------------
    Oh! do you mean it's safe to measure a 2D axis angle just to see if it's positive/negative??
    I can do that, I'm just not sure it's a good idea in 3D-space.. Yet I'm still learning..

  4. #4
    Clicker Multimedia Fusion 2Android Export Module

    Join Date
    Jan 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Vector angle math

    I do not understand your question completly. In my opinion something is missing.
    If these are all 3D vectors, them you can rotate around your current vector, so the target vector may be left, right, up down or whatever you want. For the left/right thing you need a transformation into 2D space.
    From the information in your question I cannot see, how the reduction from 3D to 2D can be done. If the vector e.g is the movement of a plane or a spaceship then the reduction could be done in relation to the "wings" of the plane/spaceship.
    Maybe you could give us a bit more information.

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    tompa's Avatar
    Join Date
    Nov 2011
    Location
    Uppsala, Sweden
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, let's see.



    Every position is a 3D-vector. Vector addition and dot product includes xyz on every instance (don't know what it's called).
    The left/right expression I used is clearly confusing lets leave that from now on. My targets angle compared to the cameras angle does not show 0-360 degrees, it shows the offset angle from the cameras current angle.
    It's 0 when I look straight at my enemy.

    The game doesn't know what side of the crosshair my soldier are supposed to appear.

    I'm not really looking at it as a graphical representation yet. I kind of just make sure the numbers are correct.
    When you say wings of a plane, do you mean top down?

  6. #6
    Clicker Multimedia Fusion 2Android Export Module

    Join Date
    Jan 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Vector angle math

    My first intention was to think about a flight simulator. There you could look top down on your plane and then a target could be left or right from the plane, which of course changes if the plane is doing a barrel roll.
    On a ground based game it might be easier to reduce the calculation to 2D as long as your character is always standing and not lying on a side.
    With 2D calculation you easily get the horizontal position and all this left/right stuff. With a second 2D calculation you get the vertical information, so your target can stand on a hill or something below you. All you need is the atan() formula from the post above. In other words, process two views: on top down and one from left to right.

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    tompa's Avatar
    Join Date
    Nov 2011
    Location
    Uppsala, Sweden
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I see, that could be interesting maybe like Comet Busters. =)

    To be honest I'm trying to learn more about 3D-spaces even if they are translated into charming 2D games. Reducing the space is not what I'm going for at this point.


    @muddy: Thanks for the formula by the way. I tried it at another instance, quite neat.

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export ModuleXNA Export Module
    tompa's Avatar
    Join Date
    Nov 2011
    Location
    Uppsala, Sweden
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found the aTan2 formula!

    a = source vector
    b = target vector

    angle = atan2(norm(cross(a,b)),dot(a,b));

    Courtesy to Roger Stafford at Mindspring.


    Though I've decided to use cosine directions instead because I instantly understood that procedure while this is a bit foreign to me.
    It's obvious that I need to learn more about euler, quaternion and matrix algebra before I confidently can program this without help from google.

Similar Threads

  1. Distance along an angle? (math)
    By alspal in forum Multimedia Fusion 2 - Technical Support
    Replies: 8
    Last Post: 7th November 2011, 07:46 AM
  2. Vector Math Object
    By Retriever2 in forum Extension Development
    Replies: 12
    Last Post: 19th October 2011, 08:12 AM
  3. angle to mouse using MATH
    By Tuna in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 4th April 2008, 04:02 AM
  4. Setting angle for a vector movement
    By Brandon in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 8th April 2007, 11:00 PM
  5. how to add to angle of vector movement
    By Deano in forum The Games Factory 2 - Technical Support
    Replies: 3
    Last Post: 31st January 2007, 02:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •