Added visibility component
This commit is contained in:
parent
5caf5f6c71
commit
7937645028
111
client/Main.tscn
111
client/Main.tscn
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=26 format=3 uid="uid://b40y7iuskv1ar"]
|
||||
[gd_scene load_steps=28 format=3 uid="uid://b40y7iuskv1ar"]
|
||||
|
||||
[ext_resource type="Script" path="res://Main.gd" id="1_cw3ws"]
|
||||
[ext_resource type="Script" path="res://network/Client.gd" id="2_8hxcx"]
|
||||
@ -14,15 +14,23 @@
|
||||
[ext_resource type="Script" path="res://world/Sun.gd" id="11_4jb08"]
|
||||
[ext_resource type="PackedScene" uid="uid://cpdoq0oh84mfw" path="res://camera/Camera.tscn" id="12_aljdh"]
|
||||
[ext_resource type="Environment" uid="uid://dixa0yso2s1u3" path="res://world/Environment.tres" id="12_cscto"]
|
||||
[ext_resource type="Script" path="res://world/Generate.gd" id="15_25nmg"]
|
||||
[ext_resource type="PackedScene" uid="uid://cb2t7bvvf3gwh" path="res://enemy/slime/Slime.tscn" id="15_hgl78"]
|
||||
[ext_resource type="Script" path="res://world/PlayerManager.gd" id="16_dp6bj"]
|
||||
[ext_resource type="PackedScene" uid="uid://dagn5bf7ou3sd" path="res://ui/UI.tscn" id="17_43qhq"]
|
||||
[ext_resource type="Material" uid="uid://bdsblfaxbipaa" path="res://world/grass/GrassMaterial.tres" id="18_tja64"]
|
||||
[ext_resource type="MultiMesh" uid="uid://dog5aq5n2q025" path="res://assets/grass/grass.multimesh" id="19_ae26a"]
|
||||
[ext_resource type="PackedScene" uid="uid://cm0rho6adv2p7" path="res://world/water/Water.tscn" id="20_bmo3k"]
|
||||
[ext_resource type="PackedScene" uid="uid://cuuwwdce1u8n8" path="res://world/trees/Sapling.tscn" id="22_5yt7w"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0w38xjifulq6" path="res://assets/house/House.blend" id="23_5j7b3"]
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_ql20k"]
|
||||
seed = 1337
|
||||
frequency = 0.05
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_yp2fx"]
|
||||
seed = 100
|
||||
frequency = 0.1
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_he5c5"]
|
||||
diffuse_mode = 3
|
||||
albedo_color = Color(0.0117647, 0.501961, 0.376471, 1)
|
||||
@ -30,10 +38,9 @@ emission = Color(0.00294706, 0.262987, 0.194557, 1)
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_lb6xk"]
|
||||
material = SubResource("StandardMaterial3D_he5c5")
|
||||
size = Vector2(25, 25)
|
||||
size = Vector2(1, 1)
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_yg2lt"]
|
||||
size = Vector3(100, 1, 100)
|
||||
|
||||
[node name="Main" type="Node"]
|
||||
script = ExtResource("1_cw3ws")
|
||||
@ -106,56 +113,22 @@ shadow_enabled = true
|
||||
script = ExtResource("11_4jb08")
|
||||
|
||||
[node name="Trees" type="Node3D" parent="World"]
|
||||
|
||||
[node name="Sapling" parent="World/Trees" instance=ExtResource("22_5yt7w")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.3131, 0, 4.6593)
|
||||
|
||||
[node name="Sapling2" parent="World/Trees" instance=ExtResource("22_5yt7w")]
|
||||
transform = Transform3D(0.484611, 0, -0.87473, 0, 1, 0, 0.87473, 0, 0.484611, 9.26825, 0, -9.34497)
|
||||
|
||||
[node name="Sapling3" parent="World/Trees" instance=ExtResource("22_5yt7w")]
|
||||
transform = Transform3D(0.398509, 0, 0.917164, 0, 1, 0, -0.917164, 0, 0.398509, 7.91727, 0, 8.5787)
|
||||
script = ExtResource("15_25nmg")
|
||||
scene = ExtResource("22_5yt7w")
|
||||
noise = SubResource("FastNoiseLite_ql20k")
|
||||
size_x = 100.0
|
||||
size_z = 100.0
|
||||
step = 5.0
|
||||
density = 0.3
|
||||
|
||||
[node name="Enemies" type="Node3D" parent="World"]
|
||||
|
||||
[node name="Slime" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -3.79687)
|
||||
|
||||
[node name="Slime4" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 1.37742, 1.28057, 9.85779)
|
||||
|
||||
[node name="Slime5" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2.00287, 1.28057, 8.21748)
|
||||
|
||||
[node name="Slime6" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.34112, 1.28057, 10.4239)
|
||||
|
||||
[node name="Slime7" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.16031, 1.28057, 9.27569)
|
||||
|
||||
[node name="Slime8" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.94264, 1.28057, 7.91351)
|
||||
|
||||
[node name="Slime9" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -9.94264, 1.28057, 0.495064)
|
||||
|
||||
[node name="Slime10" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -8.80971, 1.28057, -0.975526)
|
||||
|
||||
[node name="Slime11" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.41412, 1.28057, -9.61036)
|
||||
|
||||
[node name="Slime12" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.40571, 1.28057, -11.0707)
|
||||
|
||||
[node name="Slime13" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.04643, 1.28057, -10.0513)
|
||||
|
||||
[node name="Slime2" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.00829, 1.28057, -1.95247)
|
||||
|
||||
[node name="Slime3" parent="World/Enemies" instance=ExtResource("15_hgl78")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.53558, 1.28057, -0.306177)
|
||||
script = ExtResource("15_25nmg")
|
||||
scene = ExtResource("15_hgl78")
|
||||
noise = SubResource("FastNoiseLite_yp2fx")
|
||||
size_x = 100.0
|
||||
size_z = 100.0
|
||||
step = 2.0
|
||||
density = 0.3
|
||||
|
||||
[node name="Grass" type="MultiMeshInstance3D" parent="World"]
|
||||
layers = 2
|
||||
@ -164,6 +137,7 @@ cast_shadow = 0
|
||||
multimesh = ExtResource("19_ae26a")
|
||||
|
||||
[node name="Floor" type="MeshInstance3D" parent="World"]
|
||||
transform = Transform3D(1000, 0, 0, 0, 1000, 0, 0, 0, 1000, 0, 0, 0)
|
||||
mesh = SubResource("PlaneMesh_lb6xk")
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="World/Floor"]
|
||||
@ -172,39 +146,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="World/Floor/StaticBody3D"]
|
||||
shape = SubResource("BoxShape3D_yg2lt")
|
||||
|
||||
[node name="Ocean" type="Node3D" parent="World"]
|
||||
|
||||
[node name="Water" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water2" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, 25)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water3" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 25)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water4" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 25)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water5" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, 0)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water6" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -25, 0, -25)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water7" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -25)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Water8" parent="World/Ocean" instance=ExtResource("20_bmo3k")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 25, 0, -25)
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="House" parent="World" instance=ExtResource("23_5j7b3")]
|
||||
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, -6.04985, 0, -6.15938)
|
||||
|
||||
|
@ -20,7 +20,7 @@ attributes = ExtResource("3_olar0")
|
||||
current = true
|
||||
fov = 45.0
|
||||
size = 10.0
|
||||
far = 1000.0
|
||||
far = 150.0
|
||||
script = ExtResource("2_pwdc2")
|
||||
|
||||
[node name="CameraRays" type="Node3D" parent="Pivot"]
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
[resource]
|
||||
exposure_multiplier = 0.5
|
||||
dof_blur_far_transition = 50.0
|
||||
dof_blur_far_transition = 140.0
|
||||
dof_blur_near_enabled = true
|
||||
dof_blur_near_distance = 1.8
|
||||
dof_blur_amount = 0.02
|
||||
|
@ -25,19 +25,19 @@ func drop_loot():
|
||||
loot.global_position = owner.global_position + loot.position
|
||||
|
||||
func die():
|
||||
set_alive(false)
|
||||
DeathComponent.set_physics(owner, false)
|
||||
hud.visible = false
|
||||
animation.play("slime_death")
|
||||
|
||||
func revive():
|
||||
health.restore()
|
||||
set_alive(true)
|
||||
DeathComponent.set_physics(owner, true)
|
||||
hud.visible = true
|
||||
(owner as Node3D).transform = Transform3D.IDENTITY
|
||||
owner.global_position = respawn_position
|
||||
animation.play("slime_idle")
|
||||
|
||||
|
||||
func set_alive(alive: bool):
|
||||
owner.propagate_call("set_process", [alive])
|
||||
owner.propagate_call("set_physics_process", [alive])
|
||||
owner.get_node("Collision").call_deferred("set_disabled", !alive)
|
||||
hud.visible = alive
|
||||
static func set_physics(obj: Node3D, alive: bool):
|
||||
obj.propagate_call("set_process", [alive])
|
||||
obj.propagate_call("set_physics_process", [alive])
|
||||
obj.get_node("Collision").call_deferred("set_disabled", !alive)
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=14 format=3 uid="uid://cb2t7bvvf3gwh"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://cb2t7bvvf3gwh"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://b358op5h1y83m" path="res://assets/slime/Slime.blend" id="1_1h1hj"]
|
||||
[ext_resource type="Script" path="res://enemy/Enemy.gd" id="1_r5888"]
|
||||
@ -8,10 +8,10 @@
|
||||
[ext_resource type="PackedScene" uid="uid://bfvudkup0xsq4" path="res://enemy/death/DeathComponent.tscn" id="6_68kgw"]
|
||||
[ext_resource type="PackedScene" uid="uid://dl4vcp04t8iyr" path="res://item/soul/Soul.tscn" id="7_i0rtb"]
|
||||
[ext_resource type="Script" path="res://enemy/EnemyController.gd" id="8_b7r6l"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8lifxuvpchu3" path="res://player/visibility/VisibilityComponent.tscn" id="9_ssc7p"]
|
||||
|
||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ub3kk"]
|
||||
height = 0.5
|
||||
radius = 0.35
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_s5ct7"]
|
||||
radius = 0.4
|
||||
|
||||
[sub_resource type="Animation" id="Animation_vjs0t"]
|
||||
resource_name = "slime_death"
|
||||
@ -60,11 +60,12 @@ 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("CylinderShape3D_ub3kk")
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.4, 0)
|
||||
shape = SubResource("SphereShape3D_s5ct7")
|
||||
|
||||
[node name="HUD" parent="." node_paths=PackedStringArray("health") instance=ExtResource("3_4jtio")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.986405, 0)
|
||||
visible = false
|
||||
health = NodePath("../Health")
|
||||
|
||||
[node name="Animation" type="AnimationPlayer" parent="."]
|
||||
@ -88,3 +89,10 @@ drop = ExtResource("7_i0rtb")
|
||||
|
||||
[node name="EnemyController" type="Node" parent="."]
|
||||
script = ExtResource("8_b7r6l")
|
||||
|
||||
[node name="Visibility" parent="." node_paths=PackedStringArray("health", "hud") instance=ExtResource("9_ssc7p")]
|
||||
health = NodePath("../Health")
|
||||
hud = NodePath("../HUD")
|
||||
hud_distance = 50.0
|
||||
physics_distance = 50.0
|
||||
render_distance = 100.0
|
||||
|
@ -8,23 +8,23 @@ const DEATH_THRESHOLD = 0.01
|
||||
|
||||
@export var max_value: float
|
||||
var value: float
|
||||
var is_dead: bool
|
||||
var is_alive: bool
|
||||
|
||||
func _ready():
|
||||
restore()
|
||||
|
||||
func restore():
|
||||
is_dead = false
|
||||
is_alive = true
|
||||
value = max_value
|
||||
value_changed.emit()
|
||||
|
||||
func take_damage(attack: DamageInstance):
|
||||
if is_dead:
|
||||
if !is_alive:
|
||||
return
|
||||
|
||||
value = clampf(value - attack.damage, 0, max_value)
|
||||
value_changed.emit()
|
||||
|
||||
if value < DEATH_THRESHOLD:
|
||||
is_dead = true
|
||||
is_alive = false
|
||||
death.emit()
|
||||
|
34
client/player/visibility/VisibilityComponent.gd
Normal file
34
client/player/visibility/VisibilityComponent.gd
Normal file
@ -0,0 +1,34 @@
|
||||
class_name VisibilityComponent
|
||||
extends Node
|
||||
|
||||
@export var health: HealthComponent
|
||||
@export var hud: HUDComponent
|
||||
@export var hud_distance: float
|
||||
@export var physics_distance: float
|
||||
@export var render_distance: float
|
||||
|
||||
var parent: Node3D
|
||||
var main_player_distance_sq: float
|
||||
|
||||
func _ready():
|
||||
parent = owner
|
||||
hud_distance *= hud_distance
|
||||
physics_distance *= physics_distance
|
||||
render_distance *= render_distance
|
||||
update_visibility()
|
||||
|
||||
func _process(_delta):
|
||||
if hud.visible:
|
||||
hud.transparency = 1.0 - (hud_distance - main_player_distance_sq) * 0.001
|
||||
|
||||
func update_visibility():
|
||||
if !Global.player:
|
||||
return
|
||||
|
||||
if !health.is_alive:
|
||||
return
|
||||
|
||||
main_player_distance_sq = parent.global_position.distance_squared_to(Global.player.global_position)
|
||||
parent.visible = main_player_distance_sq < render_distance
|
||||
hud.visible = main_player_distance_sq < hud_distance
|
||||
DeathComponent.set_physics(parent, main_player_distance_sq < physics_distance)
|
10
client/player/visibility/VisibilityComponent.tscn
Normal file
10
client/player/visibility/VisibilityComponent.tscn
Normal file
@ -0,0 +1,10 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c8lifxuvpchu3"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/visibility/VisibilityComponent.gd" id="1_lhvjf"]
|
||||
|
||||
[node name="Visibility" type="Timer"]
|
||||
wait_time = 0.5
|
||||
autostart = true
|
||||
script = ExtResource("1_lhvjf")
|
||||
|
||||
[connection signal="timeout" from="." to="." method="update_visibility"]
|
@ -150,7 +150,6 @@ zoom_out={
|
||||
[physics]
|
||||
|
||||
3d/run_on_separate_thread=true
|
||||
common/physics_ticks_per_second=180
|
||||
|
||||
[rendering]
|
||||
|
||||
|
21
client/world/Generate.gd
Normal file
21
client/world/Generate.gd
Normal file
@ -0,0 +1,21 @@
|
||||
extends Node3D
|
||||
|
||||
@export var scene: PackedScene
|
||||
@export var noise: Noise
|
||||
@export var size_x: float
|
||||
@export var size_z: float
|
||||
@export var step: float = 1
|
||||
@export var density: float
|
||||
@export var position_randomness := 1.0
|
||||
|
||||
func _ready():
|
||||
for x in range(-size_x, size_x, step):
|
||||
for z in range(-size_z, size_z, step):
|
||||
if noise.get_noise_2d(x, z) < 1 - density * 2:
|
||||
continue
|
||||
|
||||
var t := scene.instantiate() as Node3D
|
||||
t.rotation.y = randf() * TAU
|
||||
t.position.x = x + (randf() - 0.5) * position_randomness
|
||||
t.position.z = z + (randf() - 0.5) * position_randomness
|
||||
add_child(t)
|
@ -11,6 +11,9 @@ radius = 0.25
|
||||
[node name="tree" parent="." index="0"]
|
||||
layers = 4
|
||||
|
||||
[node name="leaves" parent="tree" index="0"]
|
||||
layers = 4
|
||||
|
||||
[node name="StaticBody3D" type="StaticBody3D" parent="." index="1"]
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="StaticBody3D" index="0"]
|
||||
|
Loading…
Reference in New Issue
Block a user