User Tag List

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

Thread: Event to happen when Object A is within a certain range of Object B?

  1. #1
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)

    Question Event to happen when Object A is within a certain range of Object B?

    I am trying to figure out how to make an event to measure if the player is within reach of an enemy without having to resort to invisible actives.
    The actual event should be that the player is getting close to an enemy who starts to play a "angry" animation when the player is close enough. When the player moves away the enemy should go back to its "normal" animation.

    I looked at some volume distance examples to get some references on distance events but these all have their values used to measure the distance between two objects and set an action to accordingly to another single "object", the sound.

    I cant use this method I think because I have several of the same enemy in the level and it only the enemy/enemies who is currently close to the player who should play the "angry" animation.

    Anyone have an idea how to achieve this?

  2. #2
    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)
    Use the AdvancedDirectionObject.
    Check my example at the bottom page, the solution is 3 conditions.
    Attached files Attached files

  3. #3
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Or better, check out my example. Uses only 2 conditions.
    Attached files Attached files

  4. #4
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys! Which one is the best for performance or does it not matter? (I am doing mainly flash so I need to optimize as much as possible)!

  5. #5
    Clicker Fusion 2.5 DeveloperiOS Export Module
    ChrisBurrows's Avatar
    Join Date
    May 2011
    Location
    Tasmania, Australia
    Posts
    622
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't need to optimise. You need to relax.

    1 event is not going to make any difference. 10 events is not going to make any difference. 100 events will probably not make a difference. Sounds, images and videos are what makes your file bigger. Not your code.

    In my opinion. Use code that you can understand. If you can't understand it, try and figure it out. Nothing is that inaccessible. If you have no idea what is going on, you will only run into problems later.

  6. #6
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Ok thanks! I implemented the method and it works perfectly!

  7. #7
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Ok, so this event worked very nice! But now I am trying to do it a bit differently with another enemy. This enemy should also have a detection range for when it gets angry, BUT it need also to face the player. I have tried to play around with the Dirdiff commands and to have a condition of both distance and direction difference value needing to be close enough. But I just cant get this dirdiff value right :/ I think I could be close to figuring it out, but some help would be very welcome to

  8. #8
    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)
    To build an 'invisible detector' or 'line of sight', your enemys need 2 pieces of information ( theese parameters determine the shape of the detector, and should be stored in Enemies Alterable Values ):

    1 - ViewRadius_ ( A view radius )
    2 - ViewAngle_ ( A view angle )

    ...
    Your enemies need to allways remember 2 things ( theese 'must' be stored in enemys Alterable Values ):

    1 - DistToPlayer_ ( How far away in pixels they are from the player )
    2 - DirDiffToPlayer_ ( The 'absolute' ( possitive numbers only ) difference between 2 angles, ( 1 ) Enemies current facing angle/ direction, and ( 2 ) the angle between Enemies position and the Players position )

    The Advanced Direction Object can do theese calcuations using the functions:
    Dist
    DirDiffAbs
    ...
    Now lets say your Enemies should have a 'View Radius' of 150 pixels
    and a 'View Angle' of 90 degrees, you only need to do 2 thing ( Event Editor ) :

    ( 1 )
    Allways
    - Enemy set Flag0 OFF

    ( 2 )
    If DistToPlayer_ is lower or equal ViewRadius_
    + If DirDifToPlayer_ is lower or equal ViewAngle_
    - Enemy set Flag0 ON

    When Flag0 is OFF the enemy is not seeing the Player, if Flag0 is ON the enemy is seeing the player

  9. #9
    Clicker

    Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export ModuleUniversal Windows Platform Export ModuleSWF Export ModuleXNA Export Module
    Outcast's Avatar
    Join Date
    Jan 2011
    Location
    Sweden
    Posts
    3,237
    Mentioned
    9 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by King_Cool View Post
    To build an 'invisible detector' or 'line of sight', your enemys need 2 pieces of information ( theese parameters determine the shape of the detector, and should be stored in Enemies Alterable Values ):

    1 - ViewRadius_ ( A view radius )
    2 - ViewAngle_ ( A view angle )

    ...
    Your enemies need to allways remember 2 things ( theese 'must' be stored in enemys Alterable Values ):

    1 - DistToPlayer_ ( How far away in pixels they are from the player )
    2 - DirDiffToPlayer_ ( The 'absolute' ( possitive numbers only ) difference between 2 angles, ( 1 ) Enemies current facing angle/ direction, and ( 2 ) the angle between Enemies position and the Players position )

    The Advanced Direction Object can do theese calcuations using the functions:
    Dist
    DirDiffAbs
    ...
    Now lets say your Enemies should have a 'View Radius' of 150 pixels
    and a 'View Angle' of 90 degrees, you only need to do 2 thing ( Event Editor ) :

    ( 1 )
    Allways
    - Enemy set Flag0 OFF

    ( 2 )
    If DistToPlayer_ is lower or equal ViewRadius_
    + If DirDifToPlayer_ is lower or equal ViewAngle_
    - Enemy set Flag0 ON

    When Flag0 is OFF the enemy is not seeing the Player, if Flag0 is ON the enemy is seeing the player
    This looks really nice! Is there an example of how to make this? (Also I will use this detection radious in a 2D game instead of top down as it looks like here. I dont know if that will make a difference? (for example the enemy should not react when the player jumps over his head, even though the player may be very close to him)

    Maybe its even possible to paint out the actual field of vision somehow? :S

  10. #10
    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)
    There are various ways of doing something like this, but without more specific details about how the LOS should look like ( square rectangular area or pizza slice? should it rotate? ) or where on the Enemy it should be located/ originate from, its hard for me to give you a satisfying solution.
    I will however make a guess and give you a solution.

    ...
    Enemys allways need to remember:

    Allways
    - Enemy set DistanceToPlayer_ to XPlayer - XEnemy

    ...
    For Enemys to detect Player:

    ( 1 )
    Allways
    - Enemy set Flag0 OFF

    ( 2 )
    If Enemy is facing right
    +If DistanceToPlayer_ is greater than 0
    + If DistanceToPlayer_ is lower or equal to DetectionRange_
    + 'Player YBottom -1' lower or equal 'Enemy YBottom -1'
    + 'Player YBottom -1' greater or equal 'Enemy YTop'
    OR ( logical )
    If Enemy is facing right
    +If DistanceToPlayer_ is greater than 0
    + If DistanceToPlayer_ is lower or equal to DetectionRange_
    + 'Player YTop' greater or equal 'Enemy YTop'
    + 'Player YTop' lower or equal 'Enemy YBottom - 1'
    - Enemy set Flag0 ON

    If Enemy is facing left
    +If DistanceToPlayer_ is lower than 0
    + If DistanceToPlayer_ is greater or equal to DetectionRange_ *-1
    + 'Player YBottom -1' lower or equal 'Enemy YBottom -1'
    + 'Player YBottom -1' greater or equal 'Enemy YTop'
    OR ( logical )
    If Enemy is facing left
    +If DistanceToPlayer_ is lower than 0
    + If DistanceToPlayer_ is greater or equal to DetectionRange_ *-1
    + 'Player YTop' greater or equal 'Enemy YTop'
    + 'Player YTop' lower or equal 'Enemy YBottom - 1'
    - Enemy set Flag0 ON

    When Flag0 is OFF the enemy is not seeing the Player, if Flag0 is ON the enemy is seeing the player

Page 1 of 2 1 2 LastLast

Similar Threads

  1. Create Object Event
    By dcrew in forum Multimedia Fusion 2 - Technical Support
    Replies: 13
    Last Post: 13th October 2010, 02:58 AM
  2. Detect Object within a certain range
    By cchapeton in forum Multimedia Fusion 2 - Technical Support
    Replies: 4
    Last Post: 21st June 2010, 04:20 PM
  3. Object folder and Object qualifier in Global event
    By ASD in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 27th December 2009, 04:28 PM
  4. Clicking only 1 object while overlaps happen?
    By pulp in forum Multimedia Fusion 2 - Technical Support
    Replies: 10
    Last Post: 9th July 2008, 06:15 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
  •