Line of sight feature seems broken, esp. in conditions

When trying to detect whether enemies are in line of sight, I just can’t seem to get it to work, either as a condition or as an action if statement in a loop.

conditions
{
Is True For Any(Opposite Team Of(Team Of(Event Player)), Is In Line of Sight(Position Of(Event Player), Position Of(
Current Array Element), Barriers Do Not Block LOS)) == True;
}

Doesn’t work as a condition period.

But then if you do as an action instead:

actions
{
If(Is True For Any(Opposite Team Of(Team Of(Event Player)), Is In Line of Sight(Position Of(Current Array Element), Position Of(
Event Player), Barriers Do Not Block LOS)));
}

It always triggers no matter what. Even with no other players in the game.

What am I missing?

If just positions are given the Line of Sight may become radial and not just straight, if there are no players but you try to attempt requesting the position, the end position becomes 0,0,0 as coordinate, and depending on the map aligning it may become easier that a player or null vector meets the requirements and returns true. The other issue could be the option Barriers Do Not Block LOS, which may be termllogically confusing it doesn’t consider just Barriers but also Surfaces, LOS seems to have an in built function Ray Casting or Tracing as well, and the mentioned option may disable the collision checks of the underlying Ray Cast and goes through anything meaning in LOS with that option selected ignores Walls. The last issue may be that if no Player is found or the end position is not specifically a vector, the LOS returns the current selected option of the LOS value as flag number in the case of yours it returns 2 and since 2 is not 0 the boolean expression LOS gives becomes true. You may try to additionally check if the player you seek our in sight is also in appreciate View Angle to the Event Players screen with IsInViewAngle() value/action or set start position in LOS to Event Players eye position to make it more straight or angled instead of radial, and if that Player at end position is actually spawned and alive in game, last attempt would be to change the LOS option to something different, or maybe any combination of the suggestions need a try from you.

1 Like

I think you may have to check for

… Is True For Any(All Players(Opposite Team Of(Team Of(Event Player))), …

Otherwise the array that’s being used is just “Team 1” or “Team 2” which is not be the same thing as an array of all players in that team.

(And one thing to keep in mind is that Position Of() returns the position at the feet of a player’s character model, so you might want to use Eye Position() instead for the “viewing player” and/or add a Vector like Vector(0, 0, 1) to the player position(s).)

2 Likes

Here is it how it can look like with condition setup as Delwion suggested:

rule("Rule 1")
{
	event
	{
		Ongoing - Each Player;
		Team 1;
		All;
	}

	conditions
	{
		Is Alive(Event Player) == True;
		Is True For Any(All Living Players(Opposite Team Of(Team Of(Event Player))), Is In Line of Sight(Eye Position(Event Player),
			Position Of(Current Array Element) + Vector(0, 1.600, 0), Barriers Do Not Block LOS)) == True;
	}

	actions
	{
		Big Message(Event Player, Custom String("{0} is in your LOS", First Of(Filtered Array(All Living Players(Opposite Team Of(Team Of(
			Event Player))), Is In Line of Sight(Eye Position(Event Player), Position Of(Current Array Element) + Vector(0, 1.600, 0),
			Barriers Do Not Block LOS)))));
		Wait(1, Ignore Condition);
		Loop If Condition Is True;
	}
}

Shouled work, the issue was really that no Array to filter with Is True For Any was specified, Opposite Team Of is a Team structure or flag value, that can be set and provided under any Team Array related values such as All Living Players.

3 Likes

Thanks! Yeah, I incorrectly thought Team and Opposite Team Of were arrays, which led to a great deal many bugs. I’ll try to fix now.