Got a problem with duplicated NPC's gents

  • so this is my code, its kinda messy and "walk around and patrol" states dont quite work, but i can take care of that later

    imgur.com/a/LbpXq

    issue that bothers me and cant fix is: When one sprite is mirrored, others are as well. (i used masks for collision and behaviors, visuals are gonna be locked on them)

    only thing i could think of was using "for each" loop, but that didnt do it, neither is giving it to the actual visuals... I'm suspecting my saving grace is something about UID's, but i read about them, couldnt wrap my head around on how i could use them

    I really cant figure it out, would be grateful for the help!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It would be much easier if you shared a capx..

    Ok, first, event #4 should not be nested under "On start of layout". But even if you move it, it will still change state for all NPC at the same moment.

    If you want NPCs to move "chaotically" each at different time, the best way to do this is to add Timer behavior to NPC, start it for random(1,3) seconds, then On Timer event change NPC_state variable and restart the timer again for random(1,3) seconds.

    Initial "Start Timer" can be under "On start of layout" event.

    "On Timer" should be a top level event, like #1, #2 and #3.

    Event #6 is executed every tick, you should not use "Wait" inside such events, this can cause all kinds of troubles. Change your event #7 to this:

    eNPC_state=0 -> Set platform speed=0

    Else -> Set platform to maximum speed

    In event #14 as you are using "toggle boolean", when your NPC see player, they are constantly switching between being casual and annoyed about 60 times per second, because it's also triggered on every tick.

    So you need to add another condition "obj_actor_enpcmask is NOT annoyed" to event #14.

    Also, you can remove "casual" variable. NPC is either casual or annoyed, it can't be both, right? So you only need one boolean variable - annoyed.

    And finally, you don't really need "For each NPC" in any of those events, but it's ok that you have it. I believe it's a good habit to use "For each" condition, it makes the code more logical and can prevent some potential problems.

    I might have missed something, next time please share your project capx.

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