User Tag List

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11

Thread: player/enemy distance calc

  1. #1
    No Products Registered

    Join Date
    Aug 2010
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    player/enemy distance calc

    I am trying to get a little AI into the game and figured that the distance of the player from the enemy would naturally affect enemy behaviour.

    How to calculate the distance?
    I tried setting a counter pythagoras (assuming for now the player is on the left & higher than enemy):
    Sqr((X( "PLAYER" )+X( "ENEMY" )) pow 2+(Y( "PLAYER" )+Y( "ENEMY" )) pow 2)

    I was quite amazed that I managed to get this written ;o]

    In theory the counter should move to '0' the closer it gets to the enemy. It doo noot.

    I may well be completely on the wrong track here and any guidance - both on the distance thing and AI/random enemy activity generally - would be appreciated.

    thanks - ak

  2. #2
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    Hi arfa. I have a distance using a counter example on my website. Should be easy to find with the new site map.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  3. #3
    No Products Registered

    Join Date
    Aug 2010
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    Yeah, pg 9 - Distance Example
    Just downloaded and tested - great.
    I will now spend a bit of time analysing the Advanced Direction Object which I have not previously used.

    There is also "Angle and Distance Example" on pg 13 which uses pythagoras. [I see I got mine wrong - needs to be the higher minus the lower 'X' & 'Y' values squared]

    The site map works well.!
    So, many thanks nivram.

  4. #4
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    Great arfa.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  5. #5
    No Products Registered

    Join Date
    Aug 2010
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    WOW.!
    You must be sitting there waiting - ready. cool
    Slipped in while I was adding/editing to praise the site map.

    a BIG thanks

  6. #6
    No Products Registered

    Join Date
    Aug 2010
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    I tested both examples with no problem.

    Here is the Pythagoras code in a single string:
    Sqr(((X( "ENEMY" )-X( "PLAYER" )) pow 2) + ((Y( "PLAYER" )-Y( "ENEMY" )) pow 2))

    This works fine but it tracks the last-created enemy.
    So, how to deal with multiple enemies (copies/duplicates)?

    There was some info in the 'Advanced Dir Obj' help...
    "loop through the units (or unit turrets if you're using them), and on loop, you get the enemy unit objects with Get Object... and use the position of the friendly unit. Now you can get the first object's (0) distance to see if it's in range"

    but I confess it made little sense to me.

    Any leads appreciated.
    thanks

  7. #7
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module
    RickyRombo's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere between here and there
    Posts
    3,167
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    Use the ForEach object. I'm fairly certain it comes with an example?

    You could also have an event:

    * Always
    - [Unit]: Set alterable value A to distance

    * Alterable value A of [Unit] < Range
    - Fire

    or something

  8. #8
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    I also have a tower defense example that the guns only fire at the active when it is in range. That may help also.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

  9. #9
    No Products Registered

    Join Date
    Aug 2010
    Posts
    343
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    Thanks Marv - I already looked at the tower-defense but not with this in mind. I will look again.

    I think the ForEach Object will work but I enjoy resolving things from first principles as a way of learning. The maths/logic is not my strongest point so it is good to challenge the greyM atter hatter natter.

    I will get to a high speed connection one day and pull down your whole example set. It is very generous of you to make it available - even more so to accurately reference it here. thanks

  10. #10
    Forum Moderator

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export ModuleInstall Creator Pro
    nivram's Avatar
    Join Date
    Jul 2006
    Location
    Bandon, Oregon
    Posts
    6,773
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)

    Re: player/enemy distance calc

    Ok, just a thought.

    Marv
    ​458 TGF to CTF 2.5+ Examples and games
    http://www.castles-of-britain.com/mmf2examples.htm

Page 1 of 2 1 2 LastLast

Similar Threads

  1. How to increase or decrease the score based on the distance of the enemy?
    By daryuss in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 18th September 2012, 01:33 PM
  2. Enemy Follows Player Example
    By Ryan in forum File Archive
    Replies: 5
    Last Post: 25th February 2010, 02:20 PM
  3. Enemy/Player AI
    By artician in forum The Games Factory 2 - Technical Support
    Replies: 2
    Last Post: 17th May 2008, 03:26 AM
  4. Enemy is following the player
    By Rabagast in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 6th April 2008, 07:26 AM
  5. Calculating Distance from Player
    By Zenoff64 in forum Multimedia Fusion 2 - Technical Support
    Replies: 5
    Last Post: 20th January 2008, 02:18 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
  •