Need help with camera controls

Godot Version

4.1

Question

I am making camera controls for my 3d game and I've gotten the mouse controls to work but when I tried to add controller controls I got the error "Invalid get index ‘JoypadMotion’ (on base: ‘InputEventJoypadMotion’).” my code is

var rot_x = 0
var LOOKAROUND_SPEED = 0.01

func _input(event):
if event is InputEventMouseMotion or InputEventJoypadMotion:
rot_x += event.relative.x * LOOKAROUND_SPEED
transform.basis = Basis() # reset rotation
rotate_object_local(Vector3(0, -1, 0), rot_x)

Which line causes the error?

I don’t see anything in the code you posted that would lead to that specific error message, but you probably have an error in this line:

if event is InputEventMouseMotion or InputEventJoypadMotion:

Here, event is InputEventMouseMotion and InputEventJoypadMotion are evaluated as two different conditions. InputEventJoypadMotion will not check if event is of that class, but will just check if the class itself exists, so it will always betrue and the code inside the if statement will always run.

1 Like