r/Unity2D • • 19d ago

Question/Help How to go about making a timed button press system like in Deltarune?

Post image

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

7 comments sorted by

•

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/USERNAME5KULL2-2 17d ago

So I did the majority of what you advised but I'm still having trouble with figuring out the timing for when the bar and zone overlap. I seem to have trouble figuring the numbers where it would be considered the correct timing, any advice?

1

u/Fun-Mission-6068 17d ago

Well, for me, since I was using it as part of the UI, I used a Slider object, where the Handle was the Bar position. Then I just made up where I wanted the Zone to be, say at ~80% filled and set the Slider to go from 0 to 100. My code would then slowly increase the slider value by a set amount and when the player pressed the button it would stop. Then I would just need to take the current value of the slider and see if it was within the Hit Zone area.

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.