User Tag List

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

Thread: Efficient approach to Enemy LOS involving Player and Obstacles?

  1. #1
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)
    chrilley's Avatar
    Join Date
    Jul 2006
    Posts
    893
    Mentioned
    13 Post(s)
    Tagged
    1 Thread(s)

    Efficient approach to Enemy LOS involving Player and Obstacles?

    I have a little problem concerning detectors that I can't seem to figure out. More specifically how enemies can tell the difference between spotting a player and not being able to see him due to an obstacle between them.

    Behold! My artistic sketch(and notes below) to help illustrate my question:



    A) Enemies in my game will chase you down upon detecting you. To detect the player I have 1 rectangular active object act as their line of sight. If it collides with the player the enemy will rush towards him.

    B) The problem is that if the enemy happens to be behind an obstacle it will just end up continuously knock into it forever since it will try to chase the player despite being blocked.

    C) So I figured why not chase player only if the detector isn't also colliding with a wall? Well... It turns out that you can also hit an obstacle behind the player...

    I'm coming up short on ideas. Best I've got so far is that I could have the enemies fire tiny detectors like bullets. Then if they hit the player, enemy start chasing but if detector hits a wall instead it'll just simply destroy itself. However having a bunch of enemies firing a bunch of detectors each isn't very efficient on performance, especially not when I want them to instantly react to the player's presence. Fastloops also become very performance heavy once multiple enemies starts checking for a player and obstacles.

  2. #2
    Clicker Fusion 2.5Fusion 2.5+ DLC
    casleziro's Avatar
    Join Date
    Mar 2013
    Location
    United States
    Posts
    640
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Use a 1x1 dot active as the line of sight. Then, scale it on the X axis to be the distance between the enemy and player, and angle it using the angle between them. Now only chase if that line isn't overlapping an obstacle. You won't have to worry about the detector colliding with an obstacle behind the player since it always draws a line from the enemy's hotspot to the player's hotspot.

    To optimize this, you could only perform a LOS check if the player is within a certain distance of an enemy.
    It might also be better depending on the situation to make the line 2-3 pixels thick on the Y axis to avoid seeing through really thin edges between obstacles.

  3. #3
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)
    Wodjanoi's Avatar
    Join Date
    Jun 2015
    Location
    Germany
    Posts
    650
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    As a practical example and fitting addition to casleziro's post you may find the examples Line of sight and Nearest object on schrodinger's Homepage useful.

  4. #4
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCiOS Export ModuleInstall Creator Pro
    Julian82's Avatar
    Join Date
    May 2012
    Location
    outbuddies.com
    Posts
    904
    Mentioned
    43 Post(s)
    Tagged
    0 Thread(s)
    In my game I've just 3 detectors evading from the PLAYER to left, right and up. Each of them scales down when overlapping backdrops and scales up when not. If enemies overlap one of those they spot you and quickly cool down if the overlap ended (they wait some seconds in front of obstacles for you to reappear). If an enemy is not facing in the player's direction the overlaps aren't checked, so you can sneak behind them.

    It's not as precise as line of sight drawing, but very easy on resources, as you only need to do 3 background overlap checks each frame and not a scaling operation plus background check for each enemy instance. IMO 100% accurate for enemies that have a mostly horizontal platforming moving pattern (like most in your game).

    There's also one additional detector for checking melee execution range, but as this one is extremely narrow anyway I don't have to check for background overlaps there. If you're in need to check various range scenarios for different enemies you could also replace this by a simple distance calculation if the enemy was already primed by one of the players detectors.

    edit: here's a quick demonstration of the detector method (horizontal detectors only)

    https://youtu.be/bRMUfeohqoI

  5. #5
    No Products Registered

    Join Date
    Dec 2016
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does CTF not have trace hit functionality? That's kind of a basic fundamental component of game engines and has been for decades.

    But the last game I published was using a dev platform that didnt have raycast (trace hit, not the wolfenstein sprite skewing kind), and I had to resort to the bullet approach youre describing, and yes, it became a huge performance hit, so if you can avoid it,


    Sent from my iPhone using Tapatalk

  6. #6
    Clicker Fusion 2.5 DeveloperFusion 2.5+ DLCHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    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)
    chrilley's Avatar
    Join Date
    Jul 2006
    Posts
    893
    Mentioned
    13 Post(s)
    Tagged
    1 Thread(s)
    Thanks for the ideas, guys!


    I'll probably use a bit of both of your approaches casleziro & Julian82. Most enemies really just need the basic "Oh is the player in front or behind me?"check where Julian82s approach is enough. Luckily in my case I don't think I need an Up detector either!

    But I can definitely see some special enemy types that could use casleziro's method, for instance to fire off ranged attacks. My bowmen are really, really dumb atm and could use an upgrade in their targeting!

  7. #7
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    Julian's solution is surely very practical and fitting, probably more fitting than a line of sight for a platformer
    (enemies could become too much sensitive to the player unless you add an extra test for a "viewcone" maybe)

    the line-of-sight test is quite efficient though, Fusion is very fast at scaling,
    plus you can use it at its best by considering some things that (perhaps) are not immediately evident:

    1) you need just one line of sight object for testing as many enemies as needed
    2) you can fire the test only for enemies in a range
    3) you can split the test through frames if really needed, if you have a *very* large number of enemies, you might not need to draw a line for all of them in the same hundredth of second
    4) to build the line better using ATan2 for the angle (more precision than OAngle at very little additional cost, especially needed when enemies are far)
    and ODistance instead of sqr(...) (much faster and worst case you only lose a fraction of pixel in precision)

    just to lay down some additional thought as this is a pretty wide-purpose solution,
    perhaps might be useful to someone else if not for Chrilley

  8. #8
    Clicker Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Android Export Module (Steam)
    alexexhowl's Avatar
    Join Date
    Jan 2015
    Location
    RU, YKT
    Posts
    348
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    btw if you need 360 detector without using extra actives - you can use builtin line of sigh by picking all objects in a line.
    1. Pick all objects in a line (X Chaser, Y Chaser, X Player, Y Player) - set on sigh "true"
    2. If on sight "true" - set on sigh "false"
    It's works pretty good. And you can use extra events like comparing distance to limit view.

  9. #9
    Clicker Fusion 2.5Fusion 2.5 Mac
    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)
    zip2kx's Avatar
    Join Date
    Jun 2015
    Posts
    769
    Mentioned
    17 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by alexexhowl View Post
    btw if you need 360 detector without using extra actives - you can use builtin line of sigh by picking all objects in a line.
    1. Pick all objects in a line (X Chaser, Y Chaser, X Player, Y Player) - set on sigh "true"
    2. If on sight "true" - set on sigh "false"
    It's works pretty good. And you can use extra events like comparing distance to limit view.
    Oh wow I had no idea this was a thing. Fusion has so many built in things that flew under the radar for me.

  10. #10
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleiOS Export Module
    Fusion 2.5 (Steam)
    schrodinger's Avatar
    Join Date
    Nov 2014
    Posts
    3,155
    Mentioned
    27 Post(s)
    Tagged
    1 Thread(s)
    @ alexexhowl: that unfortunately proved to be buggy in the past (not detecting objects in the line) - wonder if it's been fixed since, did you use it successfully?

Page 1 of 2 1 2 LastLast

Similar Threads

  1. making enemy avoid obstacles without pathfinding object?
    By Klownzilla in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 8th September 2014, 09:18 AM
  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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •