diff --git a/client/Global.gd b/client/Global.gd index aaca3fe..e00980b 100644 --- a/client/Global.gd +++ b/client/Global.gd @@ -3,7 +3,7 @@ extends Node @export var environment: Environment @export var camera_attributes: CameraAttributesPractical -var camera: Camera3D +var camera: Camera var player: Player var players: PlayerManager var account_id: String diff --git a/client/camera/Camera.gd b/client/camera/Camera.gd index bb3e182..edccae3 100644 --- a/client/camera/Camera.gd +++ b/client/camera/Camera.gd @@ -1,5 +1,8 @@ +class_name Camera extends Camera3D +@export_flags_3d_physics var collision_mask := 1 + @export_group("Zoom") @export var zoom_speed := 0.5 @export var zoom_interpolation := 10.0 @@ -7,9 +10,12 @@ extends Camera3D @export var zoom_max := 8.0 var target_distance: float +var occlusion_distance: float = far +var pivot: Node3D func _ready(): target_distance = position.z + pivot = get_parent() Global.camera = self func _input(event): @@ -28,7 +34,38 @@ func on_distance_changed(): Global.camera_attributes.dof_blur_far_distance = target_distance + 1.0 func _process(delta): - if abs(target_distance - position.z) < 0.01: + var distance := target_distance + + if occlusion_distance < target_distance: + distance = occlusion_distance + + if abs(distance - position.z) < 0.01: return - position.z = lerpf(position.z, target_distance, zoom_interpolation * delta) \ No newline at end of file + position.z = lerpf(position.z, distance, zoom_interpolation * delta) + +func _physics_process(_delta): + occlusion_distance = far + + var corner: Vector2 = get_viewport().get_visible_rect().size + var space_state = get_world_3d().direct_space_state + + send_ray(space_state, Vector2(0, 0)) + send_ray(space_state, Vector2(corner.x, 0)) + send_ray(space_state, Vector2(0, corner.y)) + send_ray(space_state, Vector2(corner.x, corner.y)) + send_ray(space_state, Vector2(corner.x / 2, corner.y / 2)) + +func send_ray(space_state: PhysicsDirectSpaceState3D, pos: Vector2): + var from := pivot.global_position + var to := project_position(pos, -1) + var query = PhysicsRayQueryParameters3D.create(from, to, collision_mask) + var result = space_state.intersect_ray(query) + + if result: + var hit_point: Vector3 = result.position + var diff := hit_point - pivot.global_position + var distance := diff.length() + + if distance < occlusion_distance: + occlusion_distance = distance \ No newline at end of file diff --git a/client/camera/CameraPivot.gd b/client/camera/CameraPivot.gd index 7696897..b5e8636 100644 --- a/client/camera/CameraPivot.gd +++ b/client/camera/CameraPivot.gd @@ -1,6 +1,8 @@ extends Node3D @export var sensitivity: float +@export var max_rotation_x: float = 25.0 +@export var min_rotation_x: float = -80.0 var enabled: bool @@ -24,3 +26,5 @@ func _unhandled_input(event): rotation.x += deg_to_rad(-event.relative.y * sensitivity) rotation.y += deg_to_rad(-event.relative.x * sensitivity) + + rotation.x = clampf(rotation.x, deg_to_rad(min_rotation_x), deg_to_rad(max_rotation_x)) diff --git a/client/enemy/slime/Slime.tscn b/client/enemy/slime/Slime.tscn index 1dba403..be48b71 100644 --- a/client/enemy/slime/Slime.tscn +++ b/client/enemy/slime/Slime.tscn @@ -5,8 +5,9 @@ [ext_resource type="PackedScene" uid="uid://2bbycjulf00g" path="res://character/health/HealthComponent.tscn" id="2_fsqxc"] [ext_resource type="PackedScene" uid="uid://x102pryt2s5a" path="res://character/movement/MovementComponent.tscn" id="3_2phqx"] -[sub_resource type="BoxShape3D" id="BoxShape3D_x1ppt"] -size = Vector3(0.7, 0.6, 0.7) +[sub_resource type="CylinderShape3D" id="CylinderShape3D_ub3kk"] +height = 0.5 +radius = 0.35 [sub_resource type="Animation" id="Animation_qls31"] resource_name = "slime_fall" @@ -37,13 +38,15 @@ _data = { } [node name="Slime" type="CharacterBody3D" groups=["enemy"]] +collision_layer = 256 +collision_mask = 769 script = ExtResource("1_r5888") [node name="Model" parent="." instance=ExtResource("1_1h1hj")] [node name="Collision" type="CollisionShape3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0452515, 0.3, 0) -shape = SubResource("BoxShape3D_x1ppt") +shape = SubResource("CylinderShape3D_ub3kk") [node name="Animation" type="AnimationPlayer" parent="."] root_node = NodePath("../Model") diff --git a/client/item/soul/Soul.tscn b/client/item/soul/Soul.tscn index b8708cc..f594728 100644 --- a/client/item/soul/Soul.tscn +++ b/client/item/soul/Soul.tscn @@ -108,6 +108,8 @@ texture = ExtResource("1_hhudy") [node name="Area" type="Area3D" parent="."] unique_name_in_owner = true +collision_layer = 64 +collision_mask = 512 monitorable = false [node name="CollisionShape3D" type="CollisionShape3D" parent="Area"] diff --git a/client/player/Player.tscn b/client/player/Player.tscn index 2b3b7ad..3ba9e62 100644 --- a/client/player/Player.tscn +++ b/client/player/Player.tscn @@ -13,10 +13,12 @@ [ext_resource type="AnimationLibrary" uid="uid://d4n0puibh4hyt" path="res://assets/animations/human.blend" id="11_d0e6r"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_2f50n"] -radius = 0.25 +radius = 0.3 height = 1.6 [node name="Player" type="CharacterBody3D" groups=["player"]] +collision_layer = 512 +collision_mask = 769 script = ExtResource("1_8gebs") [node name="Model" type="Node3D" parent="."] diff --git a/client/project.godot b/client/project.godot index 0188191..e586554 100644 --- a/client/project.godot +++ b/client/project.godot @@ -140,6 +140,10 @@ zoom_out={ 3d_render/layer_5="Water" 3d_render/layer_9="Enemies" 3d_render/layer_10="Players" +3d_physics/layer_1="World" +3d_physics/layer_7="Loot" +3d_physics/layer_9="Enemies" +3d_physics/layer_10="Players" [physics]