User Tag List

Results 1 to 5 of 5

Thread: Angle Calculation

  1. #1
    No Products Registered

    Join Date
    Oct 2008
    Location
    Germany
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angle Calculation

    Hi folks,

    first of all: hello community. I started playing around with mmf2 a few days ago and now I have encountered the first problem I can't solve on my own.

    I am trying to create a top down shooter thingie with enemies walking around, shooting at mostly innocent players. I want to give them a line of sight to determine if they see the player or not.

    First I used an invisble object to detect the players presence, but I don't like that solution. It produces too much overhead for my taste and seems to be quite dirty. So I went over to math. I want to calculate the direction from an enemy to the player and compare that to the enemies direction. If the direction to the player is somewhere between -60° and +60° of the enemy's, then he fires a detector at the player, and if it hits him (aka not a wall), the player has been spotted.

    I put the x and y distances from the enemy to the player in alterable values, calculated the hypotenuse of these values and the arcsin of y-distance / hypotenuse.

    Sounds good to me, but unfortunetely the angles are completely wrong. Here are the angles that I get (N S W E are directions):
    N:90° E:180° S:90° W:0°

    Here is what I should get:
    N:90° E:0° S:270° w:180°

    Can anybody give me a clue whats wrong here?
    Thanks in advance,
    lincore

  2. #2
    Clicker Multimedia Fusion 2
    Algul's Avatar
    Join Date
    Feb 2008
    Posts
    230
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Angle Calculation

    ATan2(Y1-Y2,X2-X1) will give you N:90° E:0° S:-90° w:180°

  3. #3
    No Products Registered

    Join Date
    Oct 2008
    Location
    Germany
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Angle Calculation

    It works. Thanks, Algul.
    lincore

  4. #4
    No Products Registered

    Join Date
    Oct 2008
    Location
    Germany
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Angle Calculation

    For the record:
    ATan2 (Special Object>Sine and Cosine>Arc Tangent of y/x (expression)) returns a value between -180 and +180. To get correct angles from 0 to 359 degrees you have to do this (pseudocode):

    Code:
    if (atan2_result < 0) then:
        atan2_result = 360 + ANGLE;
    lincore

  5. #5
    No Products Registered

    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    1,141
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Angle Calculation

    In MMF you can use:
    Code:
    (atan2(y2-y1,x2-x1) + 360) mod 360

Similar Threads

  1. Help with angle calculation!
    By J3sseM in forum Multimedia Fusion 2 - Technical Support
    Replies: 14
    Last Post: 29th August 2013, 12:15 PM
  2. calculation help
    By aylictal in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 21st May 2013, 02:45 PM
  3. Angle calculation bug?
    By Fanotherpg in forum SWF/Flash Export Module Version 2.0
    Replies: 2
    Last Post: 23rd April 2012, 09:38 AM
  4. Movement calculation
    By Chrille in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 22nd December 2007, 11:31 PM
  5. Isometric calculation
    By MechatheSlag in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 11th September 2007, 05:55 PM

Posting Permissions

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