Error Code: "Invalid get index 'relative' (on base: 'InputEventMouseButton')."

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jared Dixon

The Error happens on this function and only appears when I left click or in my input map is “fire” that is associated with my grappling gun that is a child of the Player character

func _input(event):
	if event is InputEventMouse: #ERROR HERE
		rotate_y(deg2rad(-1 * event.relative.x) * mouse_sens)
		head.rotate_x(deg2rad(event.relative.y) * mouse_sens)
		
		# Clamp head x rotation
		head.rotation.x = clamp(head.rotation.x, deg2rad(-90), deg2rad(90))
:bust_in_silhouette: Reply From: kidscancode

There are multiple types of InputEventMouse events. A mouse button event doesn’t have a relative property, but a motion event does. You’re checking all mouse events, and therefore you get this error. Since you seem to only care about motion events, change to

if event is InputEventMouseMotion:

NICE, thank you very much, my friend, it is greatly appreciated although my grappling gun doesn’t seem to work so gotta fix that now.

Jared Dixon | 2022-03-05 13:29