User Tag List

Results 1 to 6 of 6

Thread: Calculating Distance from Player

  1. #1
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module

    Join Date
    Aug 2006
    Posts
    234
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculating Distance from Player

    Basically, I want for enemies to know when Im within a certain distance from them, and also when im not within that distance, but also to make sure they're currently on the screen as well, so I can set a flag on or off, for their attack.

    And being im mathmatically retarded, I have a hard time figuring this out.

    Could anyone post an example or aid me somehow? Many thanks in advance.

  2. #2
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Calculating Distance from Player

    http://www.clickteam.com/epicenter/ubbthreads.php?ubb=showflat&Number=73811#Post73811

    This is an example of how to do it, but it is a bit advanced.

  3. #3
    No Products Registered

    Join Date
    Jul 2006
    Location
    Texas
    Posts
    1,225
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Calculating Distance from Player

    @SEELE, sounds to me like all he wants to know is the distance formula.

    All you have to do is:
    Distance (squared) = (playerx - enemyx) pow 2 + (playery - enemyy) pow 2

    For getting the actual distance, just get the square root of that whole expression, but if you're just trying to see if the player is within a certain distance, then just leave it off, and be sure the square the distance you want it to be. Square roots take a long time to calculate, especially if you have many objects.

    So if you wanted to check if the enemy was within 100 pixels of the player, just do:
    if (playerx-enemyx) pow 2 + (playery-enemyy) pow 2 is less than or equal to 10000 then do actions

    10000 is just 100 squared.

    EDIT: @SEELE Oh I see what you're getting at, but it sounds to me like he only has 1 player object.

  4. #4
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Calculating Distance from Player

    yes, i get an extension to handle the distance calculation's(since there quicker)and simpler, but yes the idea was multi player and multi enemy handling... I think?

  5. #5
    No Products Registered

    Join Date
    Aug 2006
    Location
    UK
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Calculating Distance from Player

    The way I do it is make an invisible object that travels in front of and behind the player and the code is something like this

    If 'enemy' is overlapping 'invisible object' then go into attack mode (limit this code to once per action)

    If 'enemy' is not overlapping 'invisible object' then go into peace mode (limit this code to once per action)

    This may be what u r looking for

  6. #6
    Clicker Multimedia Fusion 2
    SEELE's Avatar
    Join Date
    Jul 2007
    Location
    Terra australis incognito
    Posts
    1,916
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Calculating Distance from Player

    There are several holes in that:

    For example if a 'second' enemy overlaps while the 'first' is still overlapping the 'second' will be ignored.

    Also this requires large objects(never a good idea in mmf(especially with fine detection enabled(such as with sight testing)))

    This is also limited to one player at a time, which is a problem most apparently in networked games.

    (sorry to be so 'narky')

Similar Threads

  1. Help with calculating time, please :)
    By Yima in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 13th August 2013, 01:24 AM
  2. player/enemy distance calc
    By arfa in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 20th October 2010, 12:56 PM
  3. Calculating text
    By richardh in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 27th February 2010, 02:09 AM
  4. Calculating bandwidth?
    By Tiny in forum Lacewing
    Replies: 8
    Last Post: 12th January 2009, 09:07 PM
  5. Calculating an arc/trajectory
    By McPhisto in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 24th March 2008, 03:53 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
  •