Note: I edited your post and clicked the "Code Sample" button to properly format your pasted code. Please make sure to do this in the future as it makes the code easier to read.
All the code after
vel.z = 0 needs to be inside the
_physics_process() function, which means it all needs to be indented. Code can't be executed outside of a function, which is why you get an "unexpected if"