Hi! One of my students is designing a fighting game where characters can hit and block. An issue we keep running into is that characters take damage even when they are not touching whenever the ‘hit’ key is pressed. We’ve tried adding a proximity function to this, but have been unsuccessful. We have not used colliders, as these will always trigger as the characters will be near each other. I’ve seen a few post mention using Filter, but we have had no success using this (I’m sure we are not using it correctly). Any help would be greatly appreciated!
https://flowlab.io/game/play/1301464
Hello @creahmc
I can see what the problem is. Every time you press the [Q] key, it just tells the knight to just lose health. What you need is a switch trigger. If done correctly, it should be something like this:
However, I did indeed notice that the health bar wasn’t going down. So I also fixed that. Change the settings to this:
And thus it should work. As for the blocking, I do not have a solution to do that. You may need help with the blocking portion of your game.
Hopefully this helped!
I cannot provide screenshots since I am on my phone right now, but to solve the blocking issue, you may need a switch that is shut off whenever the blocking key is pressed/held, then shut back on after a certain time period and/or when the button is released. If the switch is on, then any signals entered in the “in” input will release a signal through the “out” output, which could be connected to any behavior that would allow the character to take damage.
First, thank you so much! Your help is very valuable. We tested the code and found that with all the triggers being active into the switch, we are not getting an output from that switch. We tried taking the 'Always" block of the the off input of the switch block, but this did not stop the Q/proximity issue, but allowed the switch block to become active. Here is a screenshot of it not triggering switch. Could you help me understand what might be stopping the switch from becoming active?
Hey @creahmc the triggers fire in left->right top->bottom order, like reading a book.
In your example screenshot, here’s what is happening each frame:
- First, the Always trigger activates, turning off the switch, which is fine
- Next, the “Q” trigger activates, but the switch is still off, so the trigger fails to pass through the switch
- Finally, the Proximity trigger activates and turns the switch on, but it’s too late - the “Q” trigger is already done
If you move the “Q” trigger below the Proximity, I think that will give you the behavior you want.
@creahmc There is one very tiny error: The switch is set to be on first-thing. Change it to be off, and that should fix it.
I did not know the positions mattered… great to know! I had my student write you a small comment below:
thank you all for the help in the issue i ran into in the game i’m making.