How do I use line of sight for platformer enemies?

Just started using Construct 2? Post your questions here

Post » Mon Feb 09, 2015 1:13 pm

Hi,

I have a stationary enemy that I want to only shoot straight ahead when the player is in it's line of sight. But I only want the enemy to shoot what is in front of it (depending on which direction it is facing). So if the enemy is facing left, it will only shoot to the right, and if facing right, will only shoot to the left.

I tried using this event but the enemies don't shoot when the player is in front of them.
Image

Any help is appreciated.
B
8
Posts: 15
Reputation: 318

Post » Mon Feb 09, 2015 1:30 pm

From this pic I can see only one possible problem.
In this picture your eye will only shoot if wizard is visible exactly at the end of every second second. (no pun intended)
If you want to shoot at the player moment it sees him/her you should, instead of "Every 2.0 seconds" put variable inside eye that will act as a timer from which you will subtract dt, and then condition will be "if Enemy_Eye.variableName < 0", and you will need action "set Enemy_Eye.variableName to 2" (put together with spawn action)

EDIT:
also check "range" and "cone of view" of Line of sight behavior.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Mon Feb 09, 2015 5:34 pm

Thanks for the reply.

What's weird is that if I just have the player stand in what should be the LOS, the Eye won't shoot. I have changed the cone of view between 180 and 360, neither seem to alter the behavior, and range is default 1000px for now. Something's just not right.

I'll definitely implement a cool down timer like you mentioned.
B
8
Posts: 15
Reputation: 318

Post » Mon Feb 09, 2015 6:30 pm

Maybe something else is the problem. Can you give me capx?
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Mon Feb 09, 2015 11:29 pm

Sure, I have a capx here:

https://
dl.dropboxusercontent.com
/u/53823971/temp_images/Platform_LOS.capx

(Had to format the link weird because I don't have enough reputation to post links.)
B
8
Posts: 15
Reputation: 318

Post » Wed Feb 11, 2015 9:23 am

Have not used LOS before, so I played with it now.

It seems that cone of view must be positioned in front of the object, which is to the right, so you will have rotate object by 180 to make it look left.
(for all objects default angle 0 is to the left, so they should be drawn facing left, and then mirrored, which LOS takes into account, it seems)

Also another limitation seems to be that entire object must be inside cone of view.

So my advice would be to set Cone of View larger then needed and then set another condition which will compare player angle to eye angle. (you can put 360 if you do not have many such instances which will eat your hardware)

In example in the picture, cone of view is set to 360, and then another condition (last in line 6) limits it to 30 degrees behind enemy.

Also one more problem in your example is that you have 2 Enemies, and you text field will be overwritten by enemy who cannot see you, so it is enough that only one enemy cannot see you it will say "Player is Undetected"
You do not have the required permissions to view the files attached to this post.
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Thu Feb 12, 2015 3:21 pm

Thanks Razor for looking into this. I can't seem to find how to create that System condition posted above.

I have been messing with LOS and just can't get it to work like I expected it. I figured I could have a bunch of stationary enemies with this behavior, and have them shoot at the player when he is visible, but it just doesn't work like I'm expecting it to.

I came across this tutorial which I think will help me (or anyone with this issue):
https://www.scirra.com/tutorials/1320/p ... enemies-ai

Instead of relying on line of sight, just calculate the distance between the player an enemy for its range.
B
13
S
3
G
5
Posts: 286
Reputation: 3,193


Post » Wed Oct 28, 2015 2:15 am

Never figured it out :/ I asked ArcadeEd (who does C2 Twitch streams) and he plans to cover it for me sometime soon.
B
8
Posts: 15
Reputation: 318


Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 3 guests