Help with 'handbrake' mechanic

Godot Version

4.4

Question

Hi,

Sorry if this is dumb, I’m very new to this!
I’m currently working on a 3d racing game and I just can’t get the handbrake to work properly.
Could you please help me out a little?

The first part works just fine; if the car reverses it’s movement direction (from forward to backwards or vice versa) the brakes activate.
But the ‘handbrake’ just doesn’t work, and I have no idea why.
It prints the "Handbrake activated’ part when I press the designated button, so the input setup is fine.
It sometimes seems to work IF the first mechanic (the directional brake) is active.
I’m assuming it has something to do with the ‘else’ statement overwriting the ‘handbrake’ in every frame?
What can I do?

Thank you very much in advance!

if input_axis != 0 and sign(input_axis) != sign(velocity) and abs(velocity) > 2.0:
	engine_force = 0
	$WheelPhys_RL.brake = 50.0
	$WheelPhys_RR.brake = 50.0
        print("THIS WORKS")
	
else:
	engine_force = move_toward(engine_force, input_force, delta * ACCELERATION_RATE)
	$WheelPhys_RL.brake = 0
	$WheelPhys_RR.brake = 0

if Input.is_action_pressed("handbrake"):
	$WheelPhys_RL.brake = 5000
	$WheelPhys_RR.brake = 5000
	print("HANDBRAKE ACTIVATED!!")

You aren’t setting engine_force in your handbrake section.

1 Like

:man_facepalming:
Thank you so much! I’ve been looking at this for like half a day and didn’t realize what was missing :sweat_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.