Bool variable is not working

Hello, (sorry my english is not very well :’’)

So I’m creating a floating vehicle, I tried to add a feature like boosting and the fuel for boosting can be empty,
I made 3 boolean variables that are “Boosting?, Can Boost?, and Move Forward?”

the default Value for these Variables :

(Can Boost?) “Yes” because when the game is started, the fuel is 100%.
(Move Forward?) “No” because when the game is started, car is not moving.
(Boosting?) “No”

I tried to boosting using “shift button” like this

214435-2.jpg

I want whenever I press “shift” key (car does not moving) the fuel doesn’t decrease, so I made this

But this is weird, everytime I run the game even though I don’t press any button, when I press "Shift (InputAction Boost), the Fuel is still decreased

Did I do something wrong or there anyway to fix this?

Thank you UE4 :slight_smile:

My guess would be that your MoveForward bool is set to true immediately, because Input Axis Forward event will always fire (with zero Axis Value if nothing pressed). So you should compare current Axis Value with zero before setting MoveForward to true.

Hi there.
“Axis” Events fire every tick.
You basically set the boolean to true each tick.

Before setting the Boolean in your Axis Event, simply check whether the Axis Value is != 0

wow I don’t know the Axis event fire every tick, but how do I set the Axis Value to !=0?

sorry I’m new to this :’’’

Allright I took a look and I will go and make a blueprint. I will be back soon with a solution :slight_smile:

So I made this blueprint. It is the same for the most part, but there are a few changes. Let me give you a quick summary:

On tick: If the boosting? variable is ‘yes’ and it has fuel it will start to decrease your boosting fuel. Also If the Boosting Fuel is equal or less then 99 (Always use =< or => in a tick event. Using = can cause bugs when used in tick events) it will start to refuel your boost fuel and reset your speed and set ‘boosting?’ to ‘no’.

You can also remove the boost fuel refuel if you wish to do this in another way (for example if you are at a gas station, ‘boost fuel’ will be set to 100)

Pressing and releasing the W button will set the ‘moving forward?’ variable to ‘yes’ or ‘no’.
You can change the button if you use another key for moving forward. Also if you want moving forward to be on toggle, simply place a switch between pressed and the Boolean. Remove the link from released and placed it into B of the switch.

When the boost button is pressed it will check if the boost fuel is equal or greater then 1 (in other words: if you have fuel) and if ‘moving forward?’ is ‘yes’. It will then adjust the movement speed and set ‘boosting?’ to ‘yes’. If those conditions are not met, or the button is released, it will set the movement speed back to the default max speed and set ‘boosting?’ to ‘no’.

You can of course change the character max movespeed to a custom float variable if you have this set up.
You could choose to apply force like you did, but if your movement speed is set by a tick event (for example: inputaxis) you can simply change the max movespeed as it will keep adding up to that until the max is reached.

I hope this helps :slight_smile:
If you need anything else added to this, let me know :slight_smile:

It’s all good in the hood but no one commented on the delay node in Tick? Here’s another way:

No, you don’t want to set it haha. What he meant was to check if the axis forward value is not 0, so that it’s only getting set to true when you move forward. To check that you need a branch. Like this.