I'm new to godot, sorry if this is pretty easy.

My question is, how do I set up my enemy so that a collision box is only visible or only calls the sendHit() function to the player for a split second after the 3rd frame starts? Picture for ref: https://prnt.sc/WmA2kq3bDsjy

This is the collision box I'm trying to use: https://prnt.sc/OQgbp1tfWEVM. Sidenote- is there an easy way to flip a collisionbox or an entire kinematicbody2D? I just figured extending it to both sides would work because he's coded to always face the player.

Right now I have .75s timer that's turned on at the same time I switch to the attack animation. (3rd frame = .75s @ 4FPS) I've tried using this to set the collisionbox's collision and layer bits using a parent area2d, I've tried using a boolean 'hitting' variable so that the sendHit() only goes to the player if 'hitting' is true. I also start another timer when switching to the attack animation, about .85s, that just reverses whatever the first one did.

What method would you recommend to get this collisionbox to only send a signal if there's a collision for a specific split second during the animation?

It doesn't much matter, you can send a custom signal after you test for collision. It's checking every frame. If it's an animated sprite you could also check the frame property and send a signal on the frame you wanted if there is a collision. You could also use an area if you just wanted to see if there is a collision at that time by checking for overlaps. You can use the disabled property to make it work or not work.

Assuming you are using an AnimationPlayer you can add a method track where u can call methods at specific times, i.e. you would call a method that changes the hitting boolean on .75s and one at .85s. Or change a boolean that is checked before sending the hit to the player. I feel it would make more sense to have it controlled by the sender of the hit rather than the receiver in this case.

@fire7side said: It doesn't much matter, you can send a custom signal after you test for collision. It's checking every frame. If it's an animated sprite you could also check the frame property and send a signal on the frame you wanted if there is a collision. You could also use an area if you just wanted to see if there is a collision at that time by checking for overlaps. You can use the disabled property to make it work or not work.

Thanks. So, I can use the disabled property on the area2D? Is that not $Area2D.disabled = true or get_node("Area2D").disabled = true ? Neither works but I probably have something wrong

I'm new to godot, sorry if this is pretty easy.

My question is, how do I set up my enemy so that a collision box is only visible or only calls the sendHit() function to the player for a split second after the 3rd frame starts? Picture for ref: https://prnt.sc/WmA2kq3bDsjy

This is the collision box I'm trying to use: https://prnt.sc/OQgbp1tfWEVM. Is there an easy way to flip a collisionbox or an entire kinematicbody2D? I just figured extending it to both sides would work because he's coded to always face the player.

Right now I have .75s timer that's turned on at the same time I switch to the attack animation. (3rd frame = .75s @ 4FPS) I've tried using this to set the collisionbox's collision and layer bits using a parent area2d, I've tried using a boolean 'hitting' variable so that the sendHit() function only goes to the player if 'hitting' is true. I also start another timer when switching to the attack animation, about .85s, that just reverses whatever the first one did.

What method would you recommend to get this collisionbox to only send a signal if there's a collision for a specific split second during the animation?

@flanga said:

@fire7side said: It doesn't much matter, you can send a custom signal after you test for collision. It's checking every frame. If it's an animated sprite you could also check the frame property and send a signal on the frame you wanted if there is a collision. You could also use an area if you just wanted to see if there is a collision at that time by checking for overlaps. You can use the disabled property to make it work or not work.

Thanks. So, I can use the disabled property on the area2D? Is that not $Area2D.disabled = true or get_node("Area2D").disabled = true ? Neither works but I probably have something wrong

Hmm, I was wrong about the disabled property, but it doesn't matter because it's not going to interfere with physics. You can just leave it enabled and test for overlap when the timer is right.

6 months later