Line of Sight Workaround?

Hi all! I'm trying to figure out a way to confirm whether or not a character can 'see' an enemy. For example, he'll aim at the enemy if there's a clear line of sight but not if there's an object (like a platform or wall) in between them. To do that, I thought the easiest way would be to draw a line actor between the player and enemy using magnitude as the width, but when I do this, the line fails to register collisions or overlaps with any object. Is there a way to make this work?
I've attached a screenshot showing the formula I'm using for magnitude (which might be totally wrong).
If I can't get this working, I guess my next strategy will be to fire a fast, invisible bullet from the player to the enemy to determine line of sight, but that seems clunky.

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    draw a line actor between the player and enemy using magnitude as the width, but when I do this, the line fails to register collisions or overlaps with any object

    If you use the same line actor but manually place it on the scene with a non-constrained width (e.g. 20), does it register collisions?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Yes! I should have mentioned that. Unconstrained width works fine, but when I define it by the magnitude it no longer works.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    And what types of widths are you seeing when the width is constrained to the magnitude? For example, if you use a Timer and Log Debugging Statement to watch that value change (or just a Display Text behavior perhaps)?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2015

    I just made an actor constrain its width to a variable function and collide with another actor and you're right... it's not detecting the collision. I suppose this is similar to the fact that Interpolating an actor's position will prevent collision detection.

    Demo attached.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    What about firing a very fast bullet in the direction you want to check? That can have issues too since it skips pixels, but just a thought.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • karlkerschl@gmail.comkarlkerschl@gmail.com Member Posts: 5
    edited April 2015

    With a Display Text behaviour, the width reads as a variable real number of between 20 and 400 (depending on where I touch the screen in relation to the player). So it seems pretty normal and it looks like the formula works, at least. But no dice on the collision.
    I set up the invisible bullet workaround and that seems to be doing the trick - it's just that the magnitude constraint would have been such a tidy solution.

  • Thanks, @tatiang! I suspected it was akin to that interpolation problem - maybe the coordinates are just changing too quickly for it to properly detect the collision?
    I've set the invisible bullet to a speed of ~900 and the detection works. Have to test it in different scenarios but hopefully it'll hold up.
    At least now I know I'm not crazy and I can stop staring at this magnitude formula.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Glad at least one solution is working. :)

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited April 2015

    Here's a rather convoluted but pretty accurate way of achieving line of sight. It's... not the easiest method and if I'm honest I'm not sure it's the method I'd use if I was making a game, but putting it together was an interesting little experiment.

    It uses actors constrained between the player and the enemies, and only fires bullets if there's a clear line of sight. It gets around the problem of the line not detecting the collisions but looking for the collisions using the walls, not the lines.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2015

    Very nice demo, @Armelline! What I don't get though is that you did use lines and the collide rule in the Wall actor works even though the width of the lines is being constrained.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited April 2015

    @tatiang said:
    Very nice demo, Armelline! What I don't get though is that you did use lines and the collide rule in the Wall actor works even though the width of the lines is being constrained.

    The collide is being checked in the walls. Each wall has a self attribute identifying it specifically. When it overlaps with the line of sight detector, it puts a 1 in a table cell. If it doesn't, it puts a 0. Enable the display texts in the enemies to see this happening. When the player detects that there are no 1s in the table column, it fires at the actor. Otherwise, it doesn't (as at least one wall is being collided with). This is why it's a bit convoluted :D

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Right, I did turn on the Display Texts and I get how it's supposed to work -- I'm just surprised that it does. Did you try the demo I posted above? I would think an actor with a constrained width would still trigger a collision but in my example it didn't and in yours it did.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • pHghostpHghost London, UKMember Posts: 2,342

    Is this a bug?

    I think I remember seeing a tutorial on this method some time back, and as far as I remember, it used to work.

  • ArmellineArmelline Member, PRO Posts: 5,369

    Huh that is weird! I'll look at it more after supper, interesting conundrum!

  • Yeah, this demo is great, @Armeline! I just tried detecting the collision using my platforms rather than the line (as in your model, but with a simple boolean rule rather than tables) and it still didn't work for me.
    I'm using the 0.13.7 beta of the Mac Creator, for what it's worth.

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    The walls in @Armelline 's demo are doing the collision detection, and are not dynamically scaling width.

    So it is a "static" hit box.

    When the collision detection is on the dynamically scaling object, it's hitbox can no longer can detect properly.

    So it is a "dynamic" hitbox. I've never seen GS properly detect collisions on a dynamic hitbox.

    That's why @Armelline 's demo works.

    Follow us: Twitter - Website

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited April 2015

    Hah, I think I worked it out and yeah, I think it's safe to say this not working is a bug.

    Will post a demo in a second.

    Edit: Well I can't replicate it using @tatiang's demo. Will keep working on it!

  • ArmellineArmelline Member, PRO Posts: 5,369

    @AlchimiaStudios said:
    The walls in Armelline 's demo are doing the collision detection, and are not dynamically scaling width.

    So it is a "static" hit box.

    When the collision detection is on the dynamically scaling object, it's hitbox can no longer can detect properly.

    So it is a "dynamic" hitbox. I've never seen GS properly detect collisions on a dynamic hitbox.

    That's why Armelline 's demo works.

    That was my assumption making the demo. But try taking @tatiang's, and removing the constrain from the red actor. Then move it manually into the path of the white actor. Collision fails to take place :D

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    @Armelline said:
    That was my assumption making the demo. But try taking tatiang's, and removing the constrain from the red actor. Then move it manually into the path of the white actor. Collision fails to take place :D

    You're right. Hmm, very strange... :o

    Follow us: Twitter - Website

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    @Armelline when you change the layer order in @tatiang 's demo... it starts working

    Follow us: Twitter - Website

  • ArmellineArmelline Member, PRO Posts: 5,369
    edited April 2015

    @AlchimiaStudios said:
    Armelline when you change the layer order in tatiang 's demo... it starts working

    Right you are! This definitely looks like a bug then.

    Gets even weirder. It'll work even though both actors are constrained. This would imply that if you don't swap the layers, it would work with the other actor triggering the debugging statement, but it doesn't.

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    @Armelline said:
    Gets even weirder. It'll work even though both actors are constrained. This would imply that if you don't swap the layers, it would work with the other actor triggering the debugging statement, but it doesn't.

    Yeah def a weird bug. Somethings not right.

    Follow us: Twitter - Website

  • ArmellineArmelline Member, PRO Posts: 5,369

    @BlackCloakGS Any of you guys able to shed any light on this?

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited April 2015

    I'll submit it as a bug with this file.

    http://bugs.gamesalad.com/show_bug.cgi?id=926

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • AlchimiaStudiosAlchimiaStudios Member Posts: 1,069

    @tatiang said:
    I'll submit it as a bug with this file.

    http://bugs.gamesalad.com/show_bug.cgi?id=926

    Nice!

    Wonder if these are related (one is listed as ARC, so obv can't confirm):

    http://bugs.gamesalad.com/show_bug.cgi?id=869
    http://bugs.gamesalad.com/show_bug.cgi?id=219

    @BBEnk Came to a similar conclusion on the second bug listing.

    Seems to be an old bug too. Although It can sorta be worked around, it certainly isn't consistent.

    Huh, well maybe @BlackCloakGS will take a look when he gets a chance.

    Follow us: Twitter - Website

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Ah, didn't see that second one. Thanks.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • BBEnkBBEnk Member Posts: 1,764

    @AlchimiaStudios said:
    Huh, well maybe BlackCloakGS will take a look when he gets a chance.

    I tested this awhile back and it was working fine but I guess it's back again.

Sign In or Register to comment.