User Tag List

Results 1 to 8 of 8

Thread: Can someone explain to me how you find the distance between the x and y of 2 objects?

  1. #1
    Clicker

    Fusion 2.5 (Steam)

    Join Date
    Dec 2014
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can someone explain to me how you find the distance between the x and y of 2 objects?

    and remembering the rules in stupid people terms? I keep forgetting what atan2 does and ODistance is used and how its used. Is there a game dev encylcpedia that can show me what these are doing in math/trigonemtry/geometry so I can remember it in the long term?

    For instance, I know to find the distance from two points goes something like (Object1X - Object2X.... Object1Y - Object2-Y??) or whas it Object2Y then - Object1Y??????) I forget and its a headache. Im not even sure what this is doing -- only that you must do it to find the distance between two exact locations of two objects. not to mention the angles which requires cos and sin and atan2... if anyone can maybe make an example or explain it to me in this thread in stupid people that would be of great help. I'm trying to create an engine where the NPC knows the distance between and to various objects and you need to call distance functions.

    For instance, I dont understand the important of the order of inserting the objects into these equations? What does it mean when you call the ODistance for something, FROM something? Or if one object is Object1 or Object2 in the equation above??? Anyone know of a good website maybe that goes over this?

  2. #2
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    Popcorn's Avatar
    Join Date
    Jun 2006
    Location
    Norway, Bergen
    Posts
    2,366
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    I can't help you with the formula, but in Fusion, the easiest way to do what you want, is to use the Clickteam Movement Object. It has expressions to find the distance / angle between objects.

  3. #3
    Clicker Fusion 2.5 DeveloperAndroid Export Module
    Chrille's Avatar
    Join Date
    Jul 2006
    Posts
    389
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, you don't even need the Clickteam Movement Object. You can find the function in the expression editor under Special -> Distance and Angle.

  4. #4
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    There are many ways to do this in Fusion,
    each with its own pros/cons.

    Generally, builtin functions have faster performances and are quicker to use,
    but drawback is they give you integer values --> less precision.
    For distance, this is hardly a problem (you can miss one pixel..)
    for angles, this can easily be an issue, if you multiply the angle error for long ranges.

    Here are the basic options:

    Distance

    ODistance("object", x, y)
    gives you the integer distance between hot spot of "object" and x,y

    VDistance(x1,y1,x2,y2)
    gives integer distance from x1y1 to x2y2

    pythagoras:
    sqr((x1-x2)pow2 + (y1-y2) pow2)
    gives distance between x1,y1 and x2,y2
    pro: gives floating point distance
    cons: much slower than builtin functions


    Angle

    OAngle("object", x, y)
    gives the integer angle of the line joining "object" hot spot and x,y

    VAngle( x, y)
    gives the integer angle of the line joining origin of frame and x,y

    trigonometric:
    Atan2(Y2-Y1,X1-X2)
    gives the angle of the line joining 1,y1 and x2,y2
    pros: gives floating point angle
    cons: only slightly slower than builtin functions

    Other methods include extensions, like advanced direction object.

    I would go with ODistance/VDistance for distances,
    as it's faster (hardly noticeable on small number of calculations, but meaningful on very high numbers) and easier to use
    and ATan2 for angles,
    as floating point angles can make the difference, and speed is almost on-par.


    If you don't remember function names,
    you can find object related functions (O-xxx) under object - position
    and vector-related functions (V-xxx) under special - distance & angle

  5. #5
    Clicker

    Fusion 2.5 (Steam)

    Join Date
    Dec 2014
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the explanations.

  6. #6
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleSWF Export Module
    UltimateWalrus's Avatar
    Join Date
    Jul 2006
    Posts
    824
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you're that confused about atan2 and stuff like that, I highly recommend picking up a book on Trigonometry and learning the basics. It's not as difficult as it sounds and no other form of mathematics is more indispensable for game programmers. You won't be able to much of anything advanced without it.

    Finding the distance doesn't use trig functions at all though, it's just sqrt(x*x + y*y).

  7. #7
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    King_Cool's Avatar
    Join Date
    Aug 2008
    Posts
    2,335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by schrodinger View Post
    trigonometric:
    Atan2(Y2-Y1,X1-X2)
    gives the angle of the line joining 1,y1 and x2,y2
    You sure this is not backwards?
    When i do it it my Angle goes in the opposite direction ( -180 deg )
    Or maybe its because Fusions Frame 'Coordinate Origin' starts at the top-left corner...?
    If it switch X/Y 1 and 2, it works correctly.

  8. #8
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,159
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    I guess it all depends on which one you decide to be XY1 and XY2

    The Ys going "downwards" should be addressed by the fact that order is inverted
    (Y2-Y1,X1-X2 instead of Y1-Y2,X1-Y2)

    but I guess one being first and the other being second is "arbitrary"
    (so, yeah, if it comes out inverted, simply invert 1 & 2)

Similar Threads

  1. Replies: 4
    Last Post: 18th July 2014, 07:26 PM
  2. Distance between two objects
    By Panchos in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 15th November 2012, 07:47 PM
  3. Distance between 2 objects
    By qenio in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 26th June 2012, 09:12 AM
  4. Distance between objects
    By im2famous4u in forum Multimedia Fusion 2 - Technical Support
    Replies: 31
    Last Post: 18th March 2008, 10:58 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
  •