User Tag List

Results 1 to 7 of 7

Thread: Detecting line of sight between two objects?

  1. #1
    Clicker Fusion 2.5 Developer

    Join Date
    Jun 2016
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Detecting line of sight between two objects?

    So I have multiple "NPC" objects and multiple "target" objects. I'm using ODistance to have the "NPCs" move toward the nearest "target". What I'd like to do now is make it so they will only move toward their target if there is a clear line between them.

    They don't need a facing direction LoS. I want them to see in all directions at once. I just want to draw an invisible line between them and their target. If that line overlaps a backdrop, they can't see it.

    Main issue with this is that I want to have a LOT of NPCs and targets. So creating a separate LoS object that scales for each NPC or having them each shoot a stream of LoS objects won't be good for performance.

    Is there a performance friendly way of detecting if there is a backdrop between two objects? Preferably without using any additional actives?

  2. #2
    Clicker Fusion 2.5 Developer

    Join Date
    Jun 2016
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it helps, here's an example of what I'm working with. You can see right now they just charge the walls trying to get to the targets on the other side. I want them to ignore the target if there's a wall between them.
    Attached files Attached files

  3. #3
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Sumo's Avatar
    Join Date
    Jul 2008
    Posts
    642
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The best method would be to use a Line of Sight object that is one pixel in size. You would use the Xscale action to scale the one pixel to the distance between both objects. Therefore the Line of Sight object is now the size between both objects. Then use the Vector angle between two objects expression (same location where you find the distance equation) to set the angle of the Line of Sight object to always face the object it's testing. Always position the Line of Sight object to the location of the player. Now you should have a small line that's always connected between the two objects. You would test to see if any objects are overlapping this line. If there are, that means the enemy can't see the player. You can add all your objects into a qualifier group so you only have to test against that group once, instead of testing for each object you have.

    For multiple enemies, instead of creating one of these lines for each enemy, you should use fastloops to cycle between each enemy. This will be way more efficient than creating one for each enemy. Fastloops will also make this process instant. The old way would be to spread values in your enemy group, then compare the fastloops index number to the value of the enemy. Then for every loop of the fastloops, it would target only one of the enemies. Then you would do the same positioning for the Line of Sight and test. You could also check out ForEach fastloops, so it would check each enemy in the loop.

  4. #4
    Clicker Fusion 2.5 Developer

    Join Date
    Jun 2016
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the response! But I am at a loss as to how I would apply this to multiple "players"? The problem is that they aren't detecting a single player object. My game has hundreds of "NPC" objects on screen at once and they have hundreds of "Target" objects available. Are you saying that I can use a single LoS object that loops between every NPC and detects LoS on their nearest target? I can't think of a way of doing that that wouldn't obliterate the frame rate.
    Sorry if I misunderstood what you're suggesting. And thanks again for taking the time!

  5. #5
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 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)

    Join Date
    Apr 2007
    Location
    Australia
    Posts
    1,151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sumo's suggestion is the best way to do it. It would be multiple line of sight objects, each one assigned to each NPC as a child.

    Fusion 3 really needs 2D ray casting options for things like this.

  6. #6
    Clicker Fusion 2.5 Developer

    Join Date
    Jun 2016
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But then that would be hundreds of LoS objects all being scaled at once. I've attempted similar solutions to this and it always resulted in an unacceptably low frame rate. I'll go ahead and take a whack at this anyway and let you guys know how it goes.
    I was really hoping there would be some sort of solution that was equally simple to finding nearest, but would simply detect if a backdrop was present between the "NPC" position and it's "Target" position purely through numbers and without the use of scaling actives.

  7. #7
    Clicker Fusion 2.5 DeveloperiOS Export ModuleSWF Export Module
    Sumo's Avatar
    Join Date
    Jul 2008
    Posts
    642
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Sorry I missed the part that you had multiple NPCs and Enemies. In that case I would start a fastloops for the Line of Sight equal to the number of NPCs you have. Each loop will select each NPC and will try to figure out the closest enemy.

    Here's another thread that explains how to find the closest enemy:

    https://community.clickteam.com/threads/98733-Detecting-closest-object-between-multiple-objects

    Schrodinger made an example file down the page that shows how to do this. Make sure to download the second file (with the multiple objects).

    So you use that to figure out the closest one, then you select that enemy (could use its fixed value) and use the Line of Sight method to check to see if the enemy can see the NPC.

    Fastloops shouldn't obliterate the frame rate if you're optimizing it and not doing thousands of loops. With this method, you're only scaling one active at a time. You're not making a line of Sight active for each NPC. You're just going through each NPC and testing it one by one with the Line of Sight object.

Similar Threads

  1. Line of Sight example
    By Ryan in forum File Archive
    Replies: 4
    Last Post: 30th August 2010, 05:27 AM
  2. line of sight
    By willow in forum Multimedia Fusion 2 - Technical Support
    Replies: 19
    Last Post: 14th July 2010, 06:10 PM
  3. Line of Sight
    By Uzalu in forum Extension Development
    Replies: 1
    Last Post: 5th December 2009, 10:52 PM
  4. Line of sight
    By Beginier in forum File Archive
    Replies: 4
    Last Post: 24th June 2009, 05:40 PM
  5. Line of Sight Example
    By LAJ in forum File Archive
    Replies: 43
    Last Post: 29th October 2006, 02:59 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
  •