Last collision instance?

0 favourites
  • 8 posts
From the Asset Store
Perfect Particles
$2 USD
80% off
Particles support animations, collisions, effects and etc.
  • Hey there,

    In my game if you hit an enemy, it shows the damage you do above the enemy. Now i have one family called enemies. The damage works fine for each of the instances, but the damage will be shown above all of the enemies.

    The hit detection is just a box which gets spawn an checks the collision. So, all i wanna do is check the enemy which was on collision last and choose it, to show the damage above it.

    I tried a lot stuff but couldnt figure it out.

  • Usually if you set it under the same event as the collision check, it should work properly. However, if you want to set it on a different event, you can use UIDs.

    For example, create a variable called EnemyUID. When on collision and you are running your other events, set EnemyUID to enemies. UID. Than when you want to show the damage, "select enemies family by UID" than use the variable EnemyUID to select the correct enemy.

  • rekjl Thank you so much guy. The problem was, i put the whole "text appearing"-thing in an outside function. Now i put it inside the collision check itself and it works.

    Thank you!

  • Always remember, functions when called do not use the picked instance from the events that call them, you have to do the picking directly in the function itself.

    It means that in your case, you could pass the enemies.UID value as parameter of the function and as sub-event/other condition from the function event, pick enemies by UID where the value is Function.param(0) (the first parameter passed).

  • Kyatric Ok thank you! Fixed that already, but can you explain me, how exactly i can pass a value through.

    Like in this example:

    Player is on collision with enemy hit detection. Both events are seperate. No function involved here. Now i want to pass through the enemies strength-value to get subtracted from the players hitpoints. How can i pick the right value in the "player on collision"-event? Cause at the moment, the strength value is chosen by a random enemy of course.

  • Make it so that "EnemysHitDetectionBoxes" contains the UID of an "Enemys" they are tied to.

    This way, you could pick Enemys by UID and use the value of the instance variable of the "EnemysHitDetectionBoxes" your Player1Box is colliding with.

    Otherwise, consider posting your full capx, could be easier to investigate.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Kyatric

    I would like, but i cannot post a capx, cause its a commercial project.

    Anyway, i tried your method but i guess im doing something wrong? Can you check the screenshots and tell me if the picking is wrong?

    After the creation of the enemy attack, which is part of the enemy hit detection, it sets the "enemyUID-variable" of the attack, to the enemys uid which created the box.

    At the collision event it should now pick the enemys values which has the same uid as the attack-box variable, but it doesnt.

  • Kyatric

    Never mind, now it works! As usual, thank you so much for your help!

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