User Tag List

Results 1 to 7 of 7

Thread: Distance Checking for Each Object Separately.

  1. #1
    No Products Registered

    Join Date
    Oct 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Distance Checking for Each Object Separately.

    Ok, so I have a little problem, let's say I have two actives: one is calles "Enemy" and the other "Player". I want to have many instances of "Enemy" That appear over time, and I have this action:

    Condition: Check if the distance of Enemy is less than 100
    Action: Run away!

    I set up the condition as a comparison of two general values:
    Code:
    Sqr(((X( "Enemy" )-X( "Player" )) pow 2)+((Y( "Enemy" )-Y( "Player" )) pow 2))
    And the Action to run away is executed using Advanced Direction Object by setting the direction to:
    Code:
    LongDir( "Advanced Direction Object", X( "Player" ), Y( "Player" ), X( "Enemy" ), Y( "Enemy" ))
    This works perfectly if I just have one instance of Enemy..the problems arise when I have various instances:

    Problem 1: If I have, say, 3 "Enemy" objects, the event can only be triggered by one (the most recently created one)... So if for example, another enemy object is close to me it won't do anything... it has to be that one enemy.
    Problem 2: When the event does trigger, the action applies to every "Enemy" object and not just the one that triggered the event.

    I know I'm doing something wrong, I just can't find what (I'm new to MMF, been using it for a couple of days). What would you recommend I try?

    Thanks in advance.

  2. #2
    No Products Registered

    Join Date
    Dec 2006
    Posts
    1,332
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Distance Checking for Each Object Separately.

    You need to use object looping for it to work with several different objects. MMF2 has a built-in object selection system that works on single actives when there is something to identify them from the rest. To do this, most people will start an "ID" loop to differentiate the actives if they need to. Here is what you could do:

    +Start of Frame
    -Spread 0 in Alterable Value A of Enemy (This is you ID)

    +Always
    -Start loop "ID" Number of Enemy times

    +On loop "ID"
    +Alterable Value A of Enemy = LoopIndex("ID")
    +Sqr(((X( "Enemy" )-X( "Player" )) pow 2)+((Y( "Enemy" )-Y( "Player" )) pow 2)) < 100
    -Run

  3. #3
    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)

    Re: Distance Checking for Each Object Separately.

    Hey and welcome to the forums!

    EDIT: OK, Brandon beat me. Now you get two identical replies..

    First off, MMF2 comes with a built in extension that find the direction between 2 objects for you. But you allready have the expression so I guess you don't need that now

    Anyway, to test for multiple instances at the same time you have to learn how to use fastloops. If you come from a programming language, fastloop can be decribed as a for loop.

    Here's how I would it:

    Name Enemy's alterable value A to ID. You can do that in the object's property settings in the frame editor.

    * Always
    - Enemy: spread 0 into ID

    * Always
    - Start loop "Enemyunit" (number of Enemy) times

    * on loop "Enemyunit"
    + Enemy: ID equals loopindex["Enemyunit"]
    + Sqr(((X( "Enemy" )-X( "Player" )) pow 2)+((Y( "Enemy" )-Y( "Player" )) pow 2))

    - ADO: LongDir( "Advanced Direction Object", X( "Player" ), Y( "Player" ), X( "Enemy" ), Y( "Enemy" ))


    If you don't understand this, do some reading about fastloops
    OBS: You cannot spread values and start a loop in the same event. That's why I have two always conditions.

  4. #4
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Distance Checking for Each Object Separately.

    There is another, simpler solution too.
    // Set the "D" of every enemy to their distance from the player
    Always:
    -Set Alterable Value D of Enemy to Sqr(((X( "Enemy" )-X( "Player" )) pow 2)+((Y( "Enemy" )-Y( "Player" )) pow 2))
    // Compare to their "D" (Distance) from the player
    Compare to Alterable D of Enemy <= 100
    -Run Away

    In short the problem is that "compare two general values" only tests ONE object. To test them all, you can either use loops to test the objects one-by-one (the usual solution), or you can store what you want to test in an alterable value and use "Compare to Alterable" to test all the objects at once.
    Note that if there is more than one of both kinds of object (many on many) then you can't avoid using loops.
    EDIT: To do something on the "nearest" enemy, the easiest way is to store their distance in an alt value and use the "Select Object" (released extensions forum) to select the enemy with the lowest alt value.

  5. #5
    Clicker Multimedia Fusion 2 DeveloperiOS Export ModuleSWF Export Module
    Jaffob's Avatar
    Join Date
    May 2008
    Location
    USA
    Posts
    1,833
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Distance Checking for Each Object Separately.

    Quote Originally Posted by Popcorn
    First off, MMF2 comes with a built in extension that find the direction between 2 objects for you.
    Out of curiosity, what extension is this?

  6. #6
    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)

    Re: Distance Checking for Each Object Separately.

    Quote Originally Posted by Jaffob
    Quote Originally Posted by Popcorn
    First off, MMF2 comes with a built in extension that find the direction between 2 objects for you.
    Out of curiosity, what extension is this?
    Clickteam Movement Controller

  7. #7
    No Products Registered

    Join Date
    Oct 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Distance Checking for Each Object Separately.

    Quote Originally Posted by Popcorn
    Quote Originally Posted by Jaffob
    Quote Originally Posted by Popcorn
    First off, MMF2 comes with a built in extension that find the direction between 2 objects for you.
    Out of curiosity, what extension is this?
    Clickteam Movement Controller
    Also Advanced Direction Object, but somehow it made stuff act weird so I stuck to my formula :P

    @Everyone: Thanks for the help, I'll try looping then. Sounds simple enough.

Similar Threads

  1. Loading frames separately?
    By pdsoft in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 18th September 2012, 08:42 PM
  2. import alpha animation separately
    By SolarB in forum Multimedia Fusion 2 - Technical Support
    Replies: 9
    Last Post: 16th May 2012, 05:32 PM
  3. Distance checking
    By ZacQuicksilver in forum Multimedia Fusion 2 - Technical Support
    Replies: 23
    Last Post: 3rd June 2010, 09:55 PM
  4. 3 KEYS an d 3 LOCKS(checking if an object is used)
    By DEKE15 in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 10th May 2009, 09:19 AM
  5. Checking Distance for Sollthar
    By Brandon in forum File Archive
    Replies: 2
    Last Post: 23rd August 2008, 01:28 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
  •