diff --git a/camera.gd b/camera.gd new file mode 100644 index 0000000..d5398d7 --- /dev/null +++ b/camera.gd @@ -0,0 +1,15 @@ +extends Node3D + +var camera_rotation_horizontal = 0 +var starting_point = Vector2(DisplayServer.window_get_size().x / 2, DisplayServer.window_get_size().y / 2) + +func _ready(): +# Place the mouse à the center of the screen + get_viewport().warp_mouse(starting_point) + + +func _input(event): + # If right mouse button is pressed and mouse moves, pan horizontally camera + if Input.is_mouse_button_pressed( 2 ): + if event is InputEventMouseMotion: + $horizontal_root.rotate_y( event.relative.x *0.01 ) diff --git a/player.tscn b/player.tscn index 8dc2f88..50243a9 100644 --- a/player.tscn +++ b/player.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://cs8rlcwr3gu"] +[gd_scene load_steps=4 format=3 uid="uid://cs8rlcwr3gu"] [ext_resource type="PackedScene" uid="uid://b13h30ye7lv3t" path="res://character/character.tscn" id="1_718i0"] +[ext_resource type="Script" path="res://camera.gd" id="2_1s82i"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_w6qjk"] radius = 0.220923 @@ -17,6 +18,7 @@ transform = Transform3D(0.999787, 0, 0, 0, 0.589349, 0, 0, 0, 0.371542, 0, 0.836 shape = SubResource( "CapsuleShape3D_w6qjk" ) [node name="camera_root" type="Node3D" parent="."] +script = ExtResource( "2_1s82i" ) [node name="horizontal_root" type="Node3D" parent="camera_root"]