Adding horizontal pan of camera

This commit is contained in:
yannk 2022-01-20 14:59:59 +01:00
parent de408bcdbc
commit 88f41a742c
2 changed files with 18 additions and 1 deletions

15
camera.gd Normal file
View file

@ -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 )

View file

@ -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="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"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_w6qjk"]
radius = 0.220923 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" ) shape = SubResource( "CapsuleShape3D_w6qjk" )
[node name="camera_root" type="Node3D" parent="."] [node name="camera_root" type="Node3D" parent="."]
script = ExtResource( "2_1s82i" )
[node name="horizontal_root" type="Node3D" parent="camera_root"] [node name="horizontal_root" type="Node3D" parent="camera_root"]