Last collision instance?

Get help using Construct 2

Post » Wed Jan 20, 2016 12:09 pm

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.
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Wed Jan 20, 2016 12:18 pm

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.
B
46
S
23
G
31
Posts: 693
Reputation: 20,637

Post » Wed Jan 20, 2016 12:31 pm

@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!
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Wed Jan 20, 2016 1:10 pm

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).
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Tue Feb 23, 2016 3:52 pm

@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.

Image
Image
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Tue Feb 23, 2016 4:07 pm

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.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
293
S
117
G
96
Posts: 7,310
Reputation: 71,069

Post » Tue Feb 23, 2016 9:57 pm

@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.

Image
Image
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Tue Feb 23, 2016 10:24 pm

@kyatric
Never mind, now it works! As usual, thank you so much for your help!
B
11
S
3
G
2
Posts: 76
Reputation: 1,891


Return to How do I....?

Who is online

Users browsing this forum: sean080 and 9 guests