I went about the left / right movement a slightly different way, but it accomplishes the same thing. Instead of having lines for left movement, and then having lines for right movement, I used the Input.get_axis instead…
Because the left and right rotation are the same things, just in opposite directions on the same axis (one is positive, the other is negative), you can just use one if statement for both directions.
To accomplish this, create a direction variable and set it to 0. Then in the “_physics_process” you set the direction equal to the Input.get_axis and then apply_torqueue accordingly
var direction_z: float = 0 # I made it a global variable
(# all physics functions should take place in _physics_process)
func _physics_process(delta: float) → void:
direction_z = Input.get_axis(“rotate_left”,“rotate_right”)
…
if direction_z != 0:
apply_torque(Vector3(0, 0, torque_z * delta * -direction_z))
direction_z is initialized as 0 (no key pressed).
direction_z is then set to the Input.get_axis(negative direction, positive direction)
if direction_z is not equal to 0 (meaning a left or right key has been pressed)
we then apply_torque in the OPPOSITE direction_z (in Godot, + is left and - is right so a (-direction_z))
So the single if statement works because if we get back a negative number from get_axis, we know it is moving left and if we get a positive number, we know it is moving right. So in the apply_torque function, we simply pass in the OPPOSITE value to turn it in the correct direction (In short, because pushing the Left key is going to give a negative value, we have to make it positive because Godot directions are opposite on the Z plane. or else when you push Left, it will move Right.)