New LineOfSight Behaviour + UID

Get help using Construct 2

Post » Tue Jun 25, 2013 5:49 pm

Hi guys,

I'm still trying to grasp the concept of UID and understand how to use them efficiently.

In a previous thread I was suggested to use the new LineOfSight behaviour (introduced in version r134 of Cosntruct2) instead of creating my own radius and cone like I did below:



In this example, when the playable character overlaps the radius or the cone, the enemy is alerted and start chasing the PC.

I tried using the new LineOfSight behaviour to simulate the same behaviour I created above. But only one enemy detects the PC, and once the PC is detected, all enemies start chasing the PC.

I was wondering how I could maybe retrieve the UID(s) of the enemy(enemies) that has(have) the PC in line of sight. That way I could send that UID to a function that would trigger the chase.

I have created a small example of what I'm trying to achieve:



The problem here is that no enemy is really picked and don't know how to use the Line of Sight behaviour to simulate the same logic I created before.

Capx: https://www.dropbox.com/s/gby01uxyhx4a4cc/UID-hwcq5c1jzcyv.capx


Thanks a lot for your help!
B
12
S
2
Posts: 85
Reputation: 899

Post » Tue Jun 25, 2013 6:19 pm

OK, so I corrected what wasn't right and here is a functional capx.
One or 2 observations though :
- for the background, why do you use a 800x800 PNG ? Use a 32x32 one, in a tild background, and set its size to the size of the layout, that's a lot of memory free. (and the file is now 140ko, not 2Mo)
- i've put in my capx a lot of instance picking by UID, to help you understand it.
- I've gotten rid of every "every tick" and "every X sec" events using recursivity in functions. It's a nice technique to use in my opinion, and more FPS friendly.
- use the ScrollTo behavior for your player, not an "every tick, scroll to PC" ^^

Guizmus2013-06-25 18:22:54
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Tue Jun 25, 2013 6:29 pm

Thanks a lot for your help, you're the man!

I'm going to study this thoroughly! Hopefully tonight I can go to bed early thanks to you :)
B
12
S
2
Posts: 85
Reputation: 899

Post » Tue Jun 25, 2013 7:05 pm

@DoudouSupreme
I re read my post, and wanted to explain the use of recursive functions (event 6 and 7 calling themselves X second later). I use it mostly for periodical effects. Imagine you want the enemy to stop chasing the player if he ... I don't know, wants to take a nap. You can had a sub event
If enemy.stomach < 5 -> callFunction findFood
Else -> do the chase again
Can be used for debuff too, or other things :)
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Tue Jun 25, 2013 9:43 pm

That's very handy! I'll try to use that in future.

I tried to do what you said like below:



It took me to realise why it wasn't working at first, but I had forgotten to change the boolean back to false, and this was drving me nuts.

Anyway thanks for your help, it's been very insightful
B
12
S
2
Posts: 85
Reputation: 899


Return to How do I....?

Who is online

Users browsing this forum: imhotep22, plinkie and 8 guests