Problems with instance logic and more with my enemies

Not favoritedFavorited Favorited 0 favourites
  • 5 posts
From the Asset Store
100 items casual and logic games. All icons are of a high quality.
  • So i've been struggling for a while to get my enemy sprites to work individually as instances of three different object types. Here is the code for my enemy, as well as how they look in the layout:

    Here is a video to display the issue when i'm using multiple instances:

    youtu.be/CsEg2Tcx3kU

    And here is how every enemy should actually look like (the code works when there is only one enemy):

    youtu.be/hXccgbRfznc

    Each enemy is made of one instance of three object types: ENEMY_1_HITBOX (red square), ENEMY_1 (the actual enemy) and ENEMY_1_FIRE (fire under the enemy). To link them together i gave them all instance variables: ENEMY_1_ID, where i would give the sprites that should be together(eg. every sprite that makes up the first enemy) the same value, to separatethe code to the different enemies. But it simply doesn't work as it should and i feel like i've tried everything within my knowledge zone. I would really appreciate any help on this, i've been stuck for a week and a half now xD

    Here's a link to the project (drive):

    drive.google.com/drive/folders/1H5b4hMIWAr1vved2LNk8IvIIm_AsDmrN

    Thanks!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The easiest way to link three objects together is to use a container. That way, you won’t need the ID variables — picking one instance (like the hitbox) in events will automatically pick the other two objects in the same container.

    Another option is to use a hierarchy, with one object as the parent and the others as children. Then you can use "Pick parent" and "Pick children" conditions. Hierarchies also let you move all the objects as one unit.

    You can even combine both approaches: container+hierarchy for ultimate flexibility!

    .

    The way you organize your events is pretty inefficient. Running a For Each loop on every tick and nesting everything inside it (even triggers) will hurt performance, especially with many enemies. Triggers should generally not be placed inside other events.

    Never use "Trigger once" condition with objects that have multiple instances or inside loops - it only leads to bugs that are hard to debug.

    Finally, you need to tell the DEATH function which enemy instance to destroy, otherwise it may destroy the wrong enemy. Add a parameter EnemyUID, and pass enemy.UID in this parameter when calling the function.

    So the correct code should look like this:

    // Parent event
    Player on collision with Enemy
    Player is not dead yet
    
    ... // sub-events
    ... Player is immune -> Call function ENEMY_DEATH(Enemy.UID)
    ... Else -> kill the player
    
  • Hey, Thanks for the help!

    I've been rewriting my code with better logic, but i got stuck again.

    The problem is somewhere within the highlighted code. The code still works inconsistently, I want the animation to switch to "MOVE" when it moves, and to SPIN once it stops. I want it to start with animation speed = 0, and gradually increase. I did my best to use container logic to my advantage, and to avoid trigger once where i could, but i just cant get it to work.

    The code works jsut like before perfectly with just one enemy, here is a video to show the problems with multiple: https://youtu.be/A3-M1T4GZ3A

    And again here's the c3p file (named game.updated): https://drive.google.com/drive/folders/1H5b4hMIWAr1vved2LNk8IvIIm_AsDmrN?usp=sharing

    Any ideas on what's wrong with my code/what i should change or improve?

    Thanks for any help!

  • Here are some changes:

    There are 3 variables to control the spinning, you don't actually need any of them!

    Make sure to use delta-time (dt) when changing anything on every tick, like the animation speed.

    I don't understand what events 45-46 are supposed to do, so I can't tell you how to fix them.

  • Thanks! This really helped and i fixed the rest of the code, really great help.

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