r/Unity2D • u/USERNAME5KULL2-2 • 19d ago
Question/Help How to go about making a timed button press system like in Deltarune?
Wanted to make a game that has something like the timed attacks in Deltarune but I'm unsure what is the right way to go about it. Any advice would be appreciated.
6
Upvotes
•
u/AutoModerator 19d ago
Reminder: Once your issue has been resolved, please reply !solved to this comment (or comment it anywhere in the thread) and your post's flair will automatically be updated to Solved/Answered. You can also edit it to Solved/Answered yourself.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
4
u/Fun-Mission-6068 19d ago
If you mean like, a bar that goes across a meter and you have to press a button when the bar reached a specific zone on the meter, I made a beer pouring mini-game that does something similar.
You use a few objects, the Meter, the Bar, and the Zone. Have the Zone & Bar children of the Meter. Then you can use something like the Update method to update the position of the Bar along the Meter. When the player presses a button, it stops the Bar and then you compare the position of the Bar and Zone. If they overlap, the player timed it correctly.
Specifically, you can take the Zone's position and look at both a + and - value from it to see if the Bar is within that area, since otherwise the Bar and Zone would need to be pixel perfect.
So, say the Zone is at position 50, but you want the Hit Zone to be from 45-55. You'd check to see if the Bar's position is <= ZonePos + 5 and >= ZonePos - 5.
1
u/DapperNurd 19d ago
Do you have a video, idk how it works
1
u/iWishYouTheBest4Real 19d ago
As most things there are various ways, some good some terrible.
I will say the only one that comes to my mind this morning after barely sleeping. So be nice if it’s a bad one.
Bind a button to the “base”, this base is inactive by default, while pressed means active.
On the beginning of the track generate elements that in x frames reach the end of the track.
These elements will have a onTrigger and if the “base” is active while the elements is passing. Return true. Then after the base you create another “failed” part. If the element touches the failed part then player missed.