feat: add npc simulation, instancing and visual scene
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
[gd_scene load_steps=10 format=3 uid="uid://rs3hv73svbpa"]
|
[gd_scene load_steps=12 format=3 uid="uid://rs3hv73svbpa"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://4mg67crlim53" path="res://scenes/player/player.gd" id="1_o5qli"]
|
[ext_resource type="Script" uid="uid://4mg67crlim53" path="res://player/player.gd" id="1_h2yge"]
|
||||||
[ext_resource type="Script" uid="uid://ii8ai801jur2" path="res://scenes/player/camera_rig.gd" id="2_0wfyh"]
|
[ext_resource type="Script" uid="uid://ii8ai801jur2" path="res://player/camera_rig.gd" id="2_1bvp3"]
|
||||||
[ext_resource type="Script" uid="uid://dbb25ttlyogqr" path="res://scripts/simulation/SimulationManager.gd" id="3_sugp2"]
|
[ext_resource type="Script" uid="uid://dbb25ttlyogqr" path="res://simulation/SimulationManager.gd" id="3_lquwl"]
|
||||||
|
[ext_resource type="Script" uid="uid://c1f3b26n4yntf" path="res://world/world_view_manager.gd" id="4_1bvp3"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dhxxyprqflotq" path="res://player/npc/NpcVisual.tscn" id="5_lquwl"]
|
||||||
|
|
||||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_o5qli"]
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_o5qli"]
|
||||||
albedo_color = Color(0.16862746, 0.52156866, 0.30588236, 1)
|
albedo_color = Color(0.16862746, 0.52156866, 0.30588236, 1)
|
||||||
@@ -38,7 +40,7 @@ material_override = SubResource("StandardMaterial3D_o5qli")
|
|||||||
mesh = SubResource("BoxMesh_sgp6g")
|
mesh = SubResource("BoxMesh_sgp6g")
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody3D" parent="." node_paths=PackedStringArray("camera_rig")]
|
[node name="Player" type="CharacterBody3D" parent="." node_paths=PackedStringArray("camera_rig")]
|
||||||
script = ExtResource("1_o5qli")
|
script = ExtResource("1_h2yge")
|
||||||
camera_rig = NodePath("../CameraRig")
|
camera_rig = NodePath("../CameraRig")
|
||||||
|
|
||||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
|
||||||
@@ -55,7 +57,7 @@ mesh = SubResource("BoxMesh_0wfyh")
|
|||||||
|
|
||||||
[node name="CameraRig" type="Node3D" parent="." node_paths=PackedStringArray("target")]
|
[node name="CameraRig" type="Node3D" parent="." node_paths=PackedStringArray("target")]
|
||||||
transform = Transform3D(1, 0, 0, 0, 0.57357645, 0.81915206, 0, -0.81915206, 0.57357645, 0, 10, 8)
|
transform = Transform3D(1, 0, 0, 0, 0.57357645, 0.81915206, 0, -0.81915206, 0.57357645, 0, 10, 8)
|
||||||
script = ExtResource("2_0wfyh")
|
script = ExtResource("2_1bvp3")
|
||||||
target = NodePath("../Player")
|
target = NodePath("../Player")
|
||||||
follow_speed = 8.0
|
follow_speed = 8.0
|
||||||
deadzone_right = 2.0
|
deadzone_right = 2.0
|
||||||
@@ -66,11 +68,17 @@ current = true
|
|||||||
fov = 65.0
|
fov = 65.0
|
||||||
|
|
||||||
[node name="SimulationManager" type="Node" parent="."]
|
[node name="SimulationManager" type="Node" parent="."]
|
||||||
script = ExtResource("3_sugp2")
|
script = ExtResource("3_lquwl")
|
||||||
|
|
||||||
[node name="WorldViewManager" type="Node" parent="."]
|
[node name="WorldViewManager" type="Node" parent="." node_paths=PackedStringArray("simulation_manager", "active_npcs_parent")]
|
||||||
|
script = ExtResource("4_1bvp3")
|
||||||
|
npc_visual_scene = ExtResource("5_lquwl")
|
||||||
|
simulation_manager = NodePath("../SimulationManager")
|
||||||
|
active_npcs_parent = NodePath("../ActiveNPCs")
|
||||||
|
|
||||||
[node name="EventBus" type="Node" parent="."]
|
[node name="EventBus" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||||
environment = SubResource("Environment_o5qli")
|
environment = SubResource("Environment_o5qli")
|
||||||
|
|
||||||
|
[node name="ActiveNPCs" type="Node3D" parent="."]
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
extends CharacterBody3D
|
||||||
|
|
||||||
|
var sim_id: int = -1
|
||||||
|
var npc_name: String = ""
|
||||||
|
var profession: String = ""
|
||||||
|
|
||||||
|
func setup_from_sim(npc: SimNPC) -> void:
|
||||||
|
sim_id = npc.id
|
||||||
|
npc_name = npc.npc_name
|
||||||
|
profession = npc.profession
|
||||||
|
name = "NPC_%s_%s" % [sim_id, npc_name]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://bha8uf40p3sa0
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
[gd_scene load_steps=6 format=3 uid="uid://dhxxyprqflotq"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://bha8uf40p3sa0" path="res://player/npc/NpcVisual.gd" id="1_ixfoq"]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_d844k"]
|
||||||
|
|
||||||
|
[sub_resource type="CapsuleMesh" id="CapsuleMesh_d844k"]
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_d844k"]
|
||||||
|
albedo_color = Color(1, 0.22352941, 1, 1)
|
||||||
|
|
||||||
|
[sub_resource type="BoxMesh" id="BoxMesh_d844k"]
|
||||||
|
material = SubResource("StandardMaterial3D_d844k")
|
||||||
|
|
||||||
|
[node name="NpcVisual" type="CharacterBody3D"]
|
||||||
|
script = ExtResource("1_ixfoq")
|
||||||
|
|
||||||
|
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
|
||||||
|
shape = SubResource("CapsuleShape3D_d844k")
|
||||||
|
|
||||||
|
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
|
||||||
|
mesh = SubResource("CapsuleMesh_d844k")
|
||||||
|
|
||||||
|
[node name="FaceMarker" type="MeshInstance3D" parent="."]
|
||||||
|
transform = Transform3D(0.15, 0, 0, 0, 0.15, 0, 0, 0, 0.35, 0, 1.2, -0.5)
|
||||||
|
mesh = SubResource("BoxMesh_d844k")
|
||||||
@@ -9,6 +9,7 @@ var energy: float
|
|||||||
var strength: float
|
var strength: float
|
||||||
var intelligence: float
|
var intelligence: float
|
||||||
var current_task: String = "idle"
|
var current_task: String = "idle"
|
||||||
|
var position: Vector3
|
||||||
|
|
||||||
func _init(
|
func _init(
|
||||||
_id: int,
|
_id: int,
|
||||||
@@ -25,6 +26,8 @@ func _init(
|
|||||||
hunger = randf_range(20.0, 80.0)
|
hunger = randf_range(20.0, 80.0)
|
||||||
energy = randf_range(40.0, 100.0)
|
energy = randf_range(40.0, 100.0)
|
||||||
|
|
||||||
|
position = Vector3(randf_range(-8.0, 8.0), 0.0, randf_range(-8.0, 8.0))
|
||||||
|
|
||||||
func simulate_tick() -> void:
|
func simulate_tick() -> void:
|
||||||
hunger += 5.0
|
hunger += 5.0
|
||||||
energy -= 2.0
|
energy -= 2.0
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
@export var npc_visual_scene: PackedScene
|
||||||
|
@export var simulation_manager: Node
|
||||||
|
@export var active_npcs_parent: Node3D
|
||||||
|
|
||||||
|
var active_npc_visuals := {} # sim_id -> NPCVisual
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
call_deferred("spawn_initial_npcs")
|
||||||
|
|
||||||
|
func spawn_initial_npcs() -> void:
|
||||||
|
if simulation_manager == null:
|
||||||
|
push_error("WorldViewManager: simulation_manager is missing")
|
||||||
|
return
|
||||||
|
|
||||||
|
if npc_visual_scene == null:
|
||||||
|
push_error("WorldViewManager: npc_visual_scene is missing")
|
||||||
|
return
|
||||||
|
|
||||||
|
for npc in simulation_manager.npcs:
|
||||||
|
spawn_npc_visual(npc)
|
||||||
|
|
||||||
|
func spawn_npc_visual(npc: SimNPC) -> void:
|
||||||
|
if active_npc_visuals.has(npc.id):
|
||||||
|
return
|
||||||
|
|
||||||
|
var visual := npc_visual_scene.instantiate()
|
||||||
|
active_npcs_parent.add_child(visual)
|
||||||
|
|
||||||
|
visual.global_position = npc.position
|
||||||
|
visual.setup_from_sim(npc)
|
||||||
|
|
||||||
|
active_npc_visuals[npc.id] = visual
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://c1f3b26n4yntf
|
||||||
Reference in New Issue
Block a user