New LineOfSight Behaviour + UID

  • 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:

    <img src="http://img706.imageshack.us/img706/8425/xhmn.jpg" border="0" />

    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:

    <img src="http://img826.imageshack.us/img826/2535/g42f.jpg" border="0" />

    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: dropbox.com/s/gby01uxyhx4a4cc/UID-hwcq5c1jzcyv.capx

    Thanks a lot for your help!

  • 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" ^^

    <img src="https://photos-3.dropbox.com/t/0/AABtYT8MO2FfHXnH_frYkn2IltbJr4IN_hHam1bm8kWesg/12/113235847/png/1024x768/3/1372186800/0/2/LoS.PNG/PoR6-IHL1-ZjoIFilmUvpJSF-XMm2lMIO_eBw9zdMnA" border="0">

  • 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 :)

  • 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 :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • That's very handy! I'll try to use that in future.

    I tried to do what you said like below:

    <img src="http://img59.imageshack.us/img59/4544/ax23.jpg" border="0" />

    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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)