Completely Bewildering Line of Sight Stuff

For questions about using Classic.

Post » Tue Jul 13, 2010 8:42 pm

So, I'm trying to do some simple stealth gameplay using the Line of Sight behavior, but it... um... doesn't seem to be working very well.

Every guard has an 'Aware' private variable that defines whether they are patrolling (aware at 0) or attacking the player (aware at 1). The code involved is pretty simple (at least, I hope):

[code:22xxd6pw]Enemy: Has player in line of sight. >> Enemy: Set Aware to 1
Else: Enemy: Set Aware to 0[/code:22xxd6pw]

The code for what to do when an enemy does see the player is more complex:

[code:22xxd6pw]Enemy: Value 'Aware' Equal to 1 >> Enemy: Move to Player
Sub-Event:
Enemy: overlaps Player at offset 20,0
OR
Enemy: overlaps Player at offset -20,0
OR
Enemy: overlaps Player at offset 0,20
OR
Enemy: overlaps Player at offset 0,-20
Sub-Event:
Enemy: Value 'Current Cooldown' Less or equal 0 >> Enemy: Set 'Attacking to 1
>> Enemy: Set 'Current Cooldown to Enemy.Value('Attack Cooldown')[/code:22xxd6pw]

I did try to put the "Move to Player" RTS behavior command in an else statement for the is-the-enemy-adjacent-to-the-player subevent, but this caused all enemies to attack the player, regardless of whether or not they were aware of him.

Even in the current form, however, the enemy behavior is absolutely bewildering. Enemy line-of-sight appears to linger after death, and stepping into the line of sight of a destroyed enemy sometimes crashes the game. Killing any two of the three guards crashes the game. One enemy informs me that he is completely aware of the player, but nevertheless simply stands still. He'll attack the player if he moves in close, but he refuses to respond to commands (even in the above scenario, where I placed everything in an else sub-event, only the enemies who couldn't see the player attacked him - this one stayed put).

Am I just running into a bug? Or is there anything I can do to alleviate this situation?
B
1
G
2
Posts: 9
Reputation: 643

Post » Tue Jul 13, 2010 11:02 pm

[url:1oqawcpw]http://sourceforge.net/apps/mediawiki/construct/index.php?title=Families[/url:1oqawcpw]

Its all about picking.
If you have multiple's of the same object then tell the object to do something, all will do it.
You need a way to select a single object from a group of objects.
Families provide that.... as long as that single object is picked.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jul 13, 2010 11:28 pm

Well, that's the thing. I can't figure out how to pick one single object. The game seems determined to pick objects that don't exist (this seems to be what causes the crashes) or to skip over objects for no reason (the one enemy who just stands still).
B
1
G
2
Posts: 9
Reputation: 643

Post » Wed Jul 14, 2010 10:58 am

I attempted to recreate the problem with the details you provided. Don't use the OR condition. While OR works well enough in most cases, it's what is causing the crashes in your case. Not sure about the other problems. More details are needed, or a cap would be nice.
B
79
S
24
G
54
Posts: 4,749
Reputation: 40,761

Post » Wed Jul 14, 2010 3:08 pm

[quote="R0J0hound":3o6l69gf]I attempted to recreate the problem with the details you provided. Don't use the OR condition. While OR works well enough in most cases, it's what is causing the crashes in your case. Not sure about the other problems. More details are needed, or a cap would be nice.[/quote:3o6l69gf]

This seems to have partially resolved the problem, actually. Is there any chance you could explain what it is that prevents the OR condition from working in this situation?

Still pressing on with this, the ghost-line-of-sight bug still seems to be at work.

I've narrowed down one bug pretty far. The error appears to be in this section of code:



(ignore the sub-event for the player-is-in-line-of-sight event, it's for a different system and has been toggled off)

With the code as shown (all other code that refers to the Guard object or any of the families it's in has been toggled off or is in a disabled group, with the exception of a single event to enable me to destroy Enemies by clicking on them, for testing purposes), of the three guards, precisely one will cause the game to crash if he is killed and I walk into his former line of sight. There is no difference between this guard and the other guards, besides a handful of private variables related to currently disabled AI patrol routes. The bug is consistent - if the guard is dead, and the player stands in a place that would have been in the guard's line of sight at the time of his destruction, the game will crash.

There is also a "boss" sprite in the layout that is in the Enemy family, but is not the same object as the guards. Destroying this boss sprite and standing in its line of sight does not crash the game.
B
1
G
2
Posts: 9
Reputation: 643

Post » Wed Jul 14, 2010 5:13 pm

Exploring the problem further, I think the problem is that, for whatever reason, Construct insists on always running these tests for the oldest object in a Family, regardless of whether that object exists or not. This is kind of inconvenient, to say the least. Is there any obvious solution I'm missing here?
B
1
G
2
Posts: 9
Reputation: 643

Post » Wed Jul 14, 2010 6:13 pm

Might try inverting "has los" instead of having the else.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed Jul 14, 2010 8:41 pm

Tried it. The bug is still there.
B
1
G
2
Posts: 9
Reputation: 643

Post » Wed Jul 14, 2010 8:49 pm

In fact, I just tried without the ELSE event at all, and the bug was still there. The bug is definitely caused by

[code:3kij5mre]Enemy: 29 Has LOS to Player 0
> EnemySet 'Aware' to 1
[/code:3kij5mre]

And that event alone.
B
1
G
2
Posts: 9
Reputation: 643

Post » Wed Jul 14, 2010 9:45 pm

Aha!

After some additional experimentation, I was able to finally remove the bug - by toggling off the event setting line of sight for enemies to be blocked by walls!

I have no idea why this should be the case, but it appears that the line of sight bug is somehow dependent on this event as well:

[code:1opfyid9]System: 1Start of layout
> EnemyAdd LOS obstacle Wall 0
[/code:1opfyid9]

As the bug occurs with only these two events, it probably doesn't involve any others.
B
1
G
2
Posts: 9
Reputation: 643

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 8 guests