How do you add more time to pickup?

I am working on an endless runner game where the player can pick up a magnet that pulls the coins to them for 10 seconds. It turns off after that. However, If the player picks up another magnet while the current magnet is on, nothing happens. I want to change that and add blueprint scripts that will add an additional 10 seconds if player pickup another magnet.

Thank you in advance for your help

Hello Catherine8687,

You could have local boolean that tells whether the magnet is active(localMagnet). You could set localMagnet to true and false at the same time as “Magnet Active” in your character. Then you could check if it is false before casting to ThirdPersonCharacter, if true you could increment a counter. You could then check if that counter is greater than 0 right after your delay node. If true decrement the counter by one and connect back to the delay node. If false continue to your “Cast to ThirdPersonCharacter” node.

From,

I’m still pretty new to UE. Can you share screenshots of what you mentioned. Thank you again

Set up a “seconds left to magnet” float. On event tick, put a sequence. on the first path, do a branch. If “seconds left to magnet” is <0, (if true), then set “seconds left to magnet” to 0. That makes sure the magnet time will never go in the negative. you can also add at the end a branch : if “seconds left to magnet” =<0 is true, disable magnet. that disabled it. now on the other sequence branch put a branch : if “seconds left to magnet” > 0 then magnet will be enabled. picking up a magnet would just add 10 seconds to the float, and having more than 0 seconds would make it active. now add a third branch to the sequence. Put a DoOnce, then a one second delay. After the delay, -1 to “seconds left to magnet”. the output of that would re-open the DoOnce, making it so it only happens every second. There you go! that’s all set up!

You could make a function in your character that will fire off when you pickup the magnet that will count the time down and add to it if you pickup the second one while timer is already running. Very basic setup could look like this. It should be fairly easy to understand and adapt to your needs.

Thank you. This was super helpful and easy to follow.

Thanks for sharing.

I’m not sure how to add a local boolean but thanks for sharing