Force being added when button requirement isn't true

Hi all,

Looking for some help on the scripting side.

I’ve set up a jump force that I expect to only be applied when my jump button is pressed. However it seems to get applied immediately when the game is started.

I’m sure I’m doing something silly, and the fix is easy. Any help would be much appreciated.

I’ve highlighted the specific areas of the script below

Thank you in advance

6620083--754219--upload_2020-12-14_6-56-38.png

Second graphic: stray semicolon after your if statement closes the if statement so the AddForce() line is ALWAYS executed.

Your clue should be the lack of indentation on the line after the if.

Generally, you should always code this way:

if (something)
{
  DoSomeStuff();
}

Thank you very much, Kurt!

1 Like