How to rotate the camera with mouse while a mouse key is pressed?

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

Hello,
The idea:
1 You press right mouse button
2 While 1, if you move the mouse, the camera rotates

I tried this, but it gives an aberrant result (just the last part of the script):

  func _input(event):
	# keyboard inputs (xz plane movement)
	if event is InputEventKey:
		# forwards/backwards movement
		if Input.is_action_pressed("move_backwards") and Input.is_action_pressed("move_forwards"):
			pass
		elif Input.is_action_pressed("move_backwards"):
			translation += Vector3(0,0,self.xzSpeed)
		elif Input.is_action_pressed("move_forwards"):
			translation += Vector3(0, 0, -self.xzSpeed)
		# right/left movement
		if Input.is_action_pressed("move_left") and Input.is_action_pressed("move_right"):
			pass
		elif Input.is_action_pressed("move_left"):
			translation += Vector3(-self.xzSpeed, 0, 0)
		elif Input.is_action_pressed("move_right"):
			translation += Vector3(self.xzSpeed, 0, 0)
	
	elif event is InputEventMouseButton:
		if event.is_pressed():
			# zoom in
			if event.button_index == BUTTON_WHEEL_UP:
				fov -= self.zoomSpeed
			# zoom out
			if event.button_index == BUTTON_WHEEL_DOWN:
				fov += self.zoomSpeed
			
			# rotate camera
			if Input.is_action_pressed("rotate_camera"):
				var mouseDelta = event.position
				rotation_degrees += Vector3(mouseDelta.y, -mouseDelta.x, 0)
:bust_in_silhouette: Reply From: Fernando Brandt

i guess you should use this in the _physics_proccess

This is a part of the solution, but not the solution. Thanks, I think the problem is now in the rotation and the origin.

abelgutierrez99 | 2020-12-21 13:48