chore: better camera

This commit is contained in:
Varylios 2025-09-06 04:01:33 +02:00
parent b0972d502c
commit 581b42f7fb
2 changed files with 33 additions and 7 deletions

View file

@ -3,16 +3,36 @@ extends Camera3D
const SCREEN_MARGIN : int = 150 const SCREEN_MARGIN : int = 150
@export var curve : Curve
func _ready() -> void:
curve.bake()
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
var windowSize : Vector2i = get_window().size var windowSize : Vector2i = get_window().size
var mousePosition : Vector2 = get_viewport().get_mouse_position() var mousePosition : Vector2 = get_viewport().get_mouse_position()
if mousePosition.x < SCREEN_MARGIN: if mousePosition.x < SCREEN_MARGIN:
position += Vector3(-0.05, 0, 0) position.x += -0.05
if mousePosition.y < SCREEN_MARGIN: if mousePosition.y < SCREEN_MARGIN:
position += Vector3(0, 0, -0.05) position.z += -0.05
if mousePosition.x > get_window().size.x - SCREEN_MARGIN: if mousePosition.x > windowSize.x - SCREEN_MARGIN:
position += Vector3(0.05, 0, 0) position.x += 0.05
if mousePosition.y > get_window().size.y - SCREEN_MARGIN: if mousePosition.y > windowSize.y - SCREEN_MARGIN:
position += Vector3(0, 0, 0.05) position.z += 0.05
func _input(event: InputEvent) -> void:
if not event is InputEventMouseButton:
return
var newPosition : float = position.y
if event.button_index == MOUSE_BUTTON_WHEEL_UP:
newPosition = clampf(newPosition - .2, 2, 10)
elif event.button_index == MOUSE_BUTTON_WHEEL_DOWN:
newPosition = clampf(newPosition + .2, 2, 10)
rotation.x = deg_to_rad(curve.sample(newPosition))
position.y = newPosition

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=3 uid="uid://bph5gpic1arod"] [gd_scene load_steps=11 format=3 uid="uid://bph5gpic1arod"]
[ext_resource type="Script" uid="uid://qqid42jkpkmv" path="res://Levels/Scripts/WorldManager.gd" id="1_tk0a6"] [ext_resource type="Script" uid="uid://qqid42jkpkmv" path="res://Levels/Scripts/WorldManager.gd" id="1_tk0a6"]
[ext_resource type="Script" uid="uid://caf3yamufmhd4" path="res://Towers/TowerManager.gd" id="2_7pixp"] [ext_resource type="Script" uid="uid://caf3yamufmhd4" path="res://Towers/TowerManager.gd" id="2_7pixp"]
@ -6,6 +6,11 @@
[ext_resource type="Texture2D" uid="uid://o83munu8dibp" path="res://Assets/Icones/kenney_game_icons_vector.svg" id="3_6dp1o"] [ext_resource type="Texture2D" uid="uid://o83munu8dibp" path="res://Assets/Icones/kenney_game_icons_vector.svg" id="3_6dp1o"]
[ext_resource type="PackedScene" uid="uid://p6a6rb7sgeqd" path="res://UI/gui.tscn" id="6_ebgat"] [ext_resource type="PackedScene" uid="uid://p6a6rb7sgeqd" path="res://UI/gui.tscn" id="6_ebgat"]
[sub_resource type="Curve" id="Curve_c1rgm"]
_limits = [-70.0, -20.0, 2.0, 10.0]
_data = [Vector2(2, -20), 0.0, -12.5, 0, 1, Vector2(6, -70), 0.0, 0.0, 0, 0, Vector2(10, -70), 0.0, 0.0, 1, 0]
point_count = 3
[sub_resource type="Animation" id="Animation_oyb16"] [sub_resource type="Animation" id="Animation_oyb16"]
length = 0.001 length = 0.001
tracks/0/type = "value" tracks/0/type = "value"
@ -63,6 +68,7 @@ script = ExtResource("1_tk0a6")
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.5, 0.866026, 0, -0.866026, 0.5, 0, 10, 0) transform = Transform3D(1, 0, 0, 0, 0.5, 0.866026, 0, -0.866026, 0.5, 0, 10, 0)
script = ExtResource("2_c1rgm") script = ExtResource("2_c1rgm")
curve = SubResource("Curve_c1rgm")
[node name="TowerManager" type="Node3D" parent="."] [node name="TowerManager" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.73017, 0.728414, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 4.73017, 0.728414, 0)