Download

Need help with college game.

I’m struggling on how to code a process where the character has to pick up an item to keep the game going, when the player doesn’t pick up the item for any amount of time there will be a bar on the HUD that will go down. When the bar has gone all the way down the player should then explode and the game would be over.

The general idea of the game is a 3D endless runner.

I’m no programmer, but on Unreal’s Youtube channel there’s this playlist with some C++ pickup game example, maybe will be useful.

https://www.youtube.com/watch?v=mSRov77hNR4&list=PLZlv_N0_O1gYup-gvJtMsgJqnEB_dGiM4

There is also an example series on their channel with an endless runner.

Basically what you need is:
HUD widget
HUD User widget with the bar item
HUD User widget for displaying the picked up item amount, and overall time.
And maybe another for the end score screen, where you calculate pickup amount with time, and output the result.
To pickup an item set a bool value for (picked up item), and an integer for the amount, save this on the player controller, or on the GameInstance (if you going to destroy the player character upon death/time out, instead of transforming his location, and or hiding the model).

The pickup mechanic could work like this:
When the player capsule overlaps with the pickup item (requires to set Enable overlap events, for Player capsule, and the pickup item collision sphere), set the bool and integer, then destroy the item and spawn an emitter effect at that location, and a pickup sound.
The pickup item, create a blueprint, add a sphere or box collision, and then some fancy static mesh, here you also could add a rotation, for rotating coin, and some effect like glowing.

That is the basic mechanic in Lemons Must Die. The player, Mr. Lemon has Juice which is constantly draining, if it drains all the way he explodes. When he kills monsters they leave behind juice puddles which he can pick up, refilling his juice.

I have a tutorial on how to setup a shaped HUD container that empties on my blog. www.mike-purvis.com

On event begin play in your player controller set a timer that call an even or function which lowers your energy amount ( or whatever it is ), set it to looping with an interval that works for your game, 0.5 seconds or something like that. On item pick up set that player has the item for n time. Do your comparison test in the loop there to see if should lower the amount, basically it it’s n time yet. Each time you pick up the item just set the n time farther in the future.

So in other words (without the exploding part) it is like a hunger meter?

Thanks for sharing!

You’re welcome! Hope it’s useful =)