[EASY!] How would one slowly deplete or subtract a float variable?

So I’m assuming the fix for this is right under my nose, but I’m still learning BP. I’ve been making some good progress though with the help of the internet and community here.

So check this out…

As you can see, I have an InputAxis driving a thruster on a ship of mine to drive it forward. I also have “attempted” trying to set up an energy drain. When the energy drains I would like my ship to stop moving.

I tried to get it to stop for testing purposes by throwing in a branch with no luck.

How could I set this up so that while holding the inputaxis down, my energy slowly drains, and shuts off when it runs out? In my head the way I have it seems to make sense… but since it doesn’t work I’m a little confused. :slight_smile: Need a little guidance here.

I looks like you might just have the pins in the subtraction node around the wrong way. You currently have it as (0.25 - Energy), when you probably want (Energy - 0.25). If you swap them I think it should work.

The way you have it now, once energy goes below 0.25 the subtraction (0.25 - energy) is always going to be positive, so that branch will always come out true even with no energy.

Hey thanks! I actually JUST caught that like 30 seconds before I read your post. After I tested it, the energy is constantly draining now though! ?

I switched the pins and got the energy to drain… But now it’s automatically draining… How can I stop it? It’s exactly the same except with the pins switched as variss mentioned.

It seems that inputaxis is constantly firing even when I don’t actually press the buttons. Since my energy is constantly draining. I tried to plug in the axis value from the input, but that didn’t seem to do the trick.

I don’t have much experience with axis input (I’m not using them in my projects at the moment), but I think the axis inputs are constantly firing. When you aren’t touching the joystick/thumbstick on the controller, it just returns an axis value of 0. But with your setup, its still going to constantly fire off the event and reduce energy even when you aren’t moving.

You could maybe put a branch at the start of the event that tests that the Axis Value is not 0 before draining any energy and applying movement.

This is correct. Axis events fire every tick, even with no input. In that case they are 0. Just check for a threshold and you will be good.

Well I have two options here I guess. I moved my “energy drain” down to where I spawn particles on my ship for the engines.

I’m currently using “InputAxis” to move the ship forward in space, and “GamepadTrigger” and “W” Press to spawn particle emitters at the rear of the ship.

SO… After I moved my energy drain to the particle emitting section in my BP… I “SORT OF” got it to work. However, it’s only draining energy when I press the first time, release, and press again. It’s not draining constantly when the “W” key or the “Trigger” is pushed down.

So I can either make it work from the AxisInput, OR the Gamepad Trigger (Pressed) output. But it’s either constantly draining from axis input, or it won’t drain steadily from the trigger… So at least I have two options here. haha, I’m just not sure how to make it work with either one!

EDIT: How would I check it for a threshold like john had mentioned?

Look for the node “Nearly Equal (Float)”

I can’t see how that would work here…

If inputaxis is always firing, it’s always going to be firing my energy drain script. Having a nearly equal float inline won’t do me any good here will it? If so, how the hell would I plug this in? Would I be better to try to get this working on my particle emitter section with my triggers?

I would put a branch at the very start of the InputAxis MainThrust block. Plug the “axis value” variable into the A pin of the nearlyEqual node, and leave B at 0.0 (so you’re testing if axis value is nearly equal to 0). Plug the result of that into the branch at the start, and only process the rest of your nodes if the result comes out true.

Bump up the error tolerance a little if you want to have a sort of deadzone (so you only start thrusting after pushing the stick past a threshold).

were you thinking like this? It’s constantly draining like this setup if I don’t touch the buttons I have mapped to my input axis. When I touch them, the energy drain stops. Still can’t seem to get it to work though. I tried values from 0.000001 to 100. No luck.

EDIT: Looking into how to use a Gate Node with my energy drain on my triggers instead of my inputaxis.

Whoops! sorry, i had that the wrong way around, you only want to process the rest of your code if the test comes out FALSE (meaning the axis is Not 0, meaning the stick being pushed). Otherwise yeah the way you have it is what i was thinking (just change it so the execution wire comes out of the false result instead :slight_smile: )

Also you’ll probably want the error tolerance to be quite low, as the axis value is only going to return results between -1 and 1 (even the default tolerance should be fine though).

HA!! That worked Variss & John!!. You’re amazing. Comirr so I can kiss ya! Thanks guys!

This is what it looks like.