godot-third-person-basic-scene/camera.gd

17 lines
554 B
GDScript3
Raw Normal View History

2022-01-20 13:59:59 +00:00
extends Node3D
var starting_point = Vector2(DisplayServer.window_get_size().x / 2, DisplayServer.window_get_size().y / 2)
func _ready():
2022-01-20 14:04:58 +00:00
# Place the mouse at the center of the screen
2022-01-20 13:59:59 +00:00
get_viewport().warp_mouse(starting_point)
func _input(event):
# If right mouse button is pressed and mouse moves, pan horizontally camera
2022-01-20 14:04:58 +00:00
# and rotate vertically
2022-01-20 13:59:59 +00:00
if Input.is_mouse_button_pressed( 2 ):
if event is InputEventMouseMotion:
$horizontal_root.rotate_y( event.relative.x *0.01 )
2022-01-20 14:04:58 +00:00
$horizontal_root/vertical_root.rotate_x( event.relative.y * 0.01 )