Help with orbit camera

4.3

hi guys, alright so i just need some help with this issue im getting with a camera orbit script, the x axis works well but for some reason the y axis rotates it on z. im not sure why. ive tried different variations of the script but nothing really changes.

extends CharacterBody3D

@onready var center = $center
@onready var camera: Camera3D = $Camera3D

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if not is_on_floor():
		velocity += get_gravity() * delta
		
	if Input.is_action_pressed("thrust_active"):
		velocity.y += 20.0 * delta
	
	move_and_slide()
		
func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
		
		if event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
			camera.position.z += 0.5
		elif event.button_index == MOUSE_BUTTON_WHEEL_UP:
			camera.position.z -= 0.5
	elif event.is_action_pressed("ui_cancel"):
		Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
	if Input.MOUSE_MODE_CAPTURED:
		if event is InputEventMouseMotion:
			center.ROTATION_EDIT_MODE_EULER
			center.rotate_y(deg_to_rad(-event.relative.x*0.1))
			center.rotate_z(deg_to_rad(-event.relative.y*0.1))
			#center.rotation.x = clamp(camera.rotation.x, deg_to_rad(-90), deg_to_rad(45))
			
			

I think here is the problem, you wrote “rotate_z” instead of “rotate_x”.

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