Destroy Hit Detection Box

Get help using Construct 2

Post » Sat Nov 07, 2015 7:10 pm

Hey there,

When i make the player attack, it spawns a hit detection box in front of him, at a certain frame. When the attack animation is over, i used the command destroy object on the box. Now this seem to work pretty well. Now i did the same with an enemy. They got their own hit detection box, it spawns just fine, but when it comes to destroy the box after the animation, it just fails.
Is there anything i'm missing about destroying an object? Why is it working on one character but not on the other?

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

Post » Sat Nov 07, 2015 7:28 pm

Without seeing the events it is not easy to answer..
First thing that comes to mind is there are more enemies than one and one of them is still playing the animation..

But like I said, without events and/or capx it's hard to say..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 07, 2015 7:54 pm

Oh you are right, here you go.
The whole event is nested inside a "for each enemy" event. So that may be the problem?

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

Post » Sat Nov 07, 2015 9:29 pm

The image isn't showing.
I suspect that you're not picking the right box instance that is "paired" with the specific enemy instance. It works for the player probably because there's only one player object and one player-box object.
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Sat Nov 07, 2015 10:22 pm

Image

Working now?

@immortalx It's definitely the right box, i coloured player and enemy detection in different colours for testing and they both show up and the player box also got destroyed, just the enemy box seems to stay there, till the enemy attacks again, creating another box.
Thanks for your answer!
B
11
S
3
G
2
Posts: 76
Reputation: 1,891

Post » Sat Nov 07, 2015 10:36 pm

Well, you don't reference the enemy attack box in the event so there is no way for the program to know which instance of it you mean, for it is in no way related to the enemy that it is spawned by..

You are creating attack boxes every tick while frame 5 and 6 are playing, but you are also creating attack boxes while frame 7 is playing and destroying them, but a created object can't be referenced untill the next top level event..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Nov 07, 2015 11:09 pm

LittleStain has a better understanding and explained it way better than me. Maybe you could try to store the IID of the box in a variable, right after its creation.
Then, on the "Animation frame>=7" event insert a subevent "Pick Nth instance" where N=the previously stored IID and destroy the object there.
B
13
S
5
G
1
Posts: 116
Reputation: 1,805

Post » Sun Nov 08, 2015 12:11 am

Okay thank you guys, i think i understand a bit better now how construct reads the events. Gonna test it soon.
B
11
S
3
G
2
Posts: 76
Reputation: 1,891


Return to How do I....?

Who is online

Users browsing this forum: stevenode and 10 guests