Added terrain and robot prototypes

This commit is contained in:
douwe
2025-08-29 17:04:57 +02:00
parent 7c24dd92b0
commit 4e77198656
21 changed files with 342 additions and 73 deletions

109
nodes/robots/Robots.tscn Normal file
View File

@@ -0,0 +1,109 @@
[gd_scene load_steps=18 format=3 uid="uid://b84ihb5xw37pm"]
[ext_resource type="PackedScene" uid="uid://cy0nvmw51bwof" path="res://nodes/camera/controllable_camera.tscn" id="1_ecqtg"]
[ext_resource type="Script" uid="uid://bnw0h8cuyf3g5" path="res://nodes/robots/robot.gd" id="1_nnl6p"]
[ext_resource type="VoxelBlockyLibrary" uid="uid://bsue4rd3wdfsl" path="res://nodes/word/BlockLibrary.tres" id="1_r886l"]
[ext_resource type="Material" uid="uid://de6s8en5fcyyw" path="res://nodes/word/BlockMaterial.tres" id="2_nnl6p"]
[ext_resource type="PackedScene" uid="uid://ddyulj4dsrkms" path="res://nodes/word/terrain_editor.tscn" id="4_llm6e"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_e1sxe"]
sky_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
ground_horizon_color = Color(0.662243, 0.671743, 0.686743, 1)
[sub_resource type="Sky" id="Sky_0wfyh"]
sky_material = SubResource("ProceduralSkyMaterial_e1sxe")
[sub_resource type="Environment" id="Environment_5yot8"]
background_mode = 2
sky = SubResource("Sky_0wfyh")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_o5qli"]
albedo_color = Color(0.313808, 0.455394, 0.721014, 1)
[sub_resource type="BoxMesh" id="BoxMesh_oo1c2"]
material = SubResource("StandardMaterial3D_o5qli")
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_r886l"]
albedo_color = Color(0.999686, 0.38438, 0, 1)
[sub_resource type="PrismMesh" id="PrismMesh_nnl6p"]
material = SubResource("StandardMaterial3D_r886l")
size = Vector3(0.5, 0.5, 0.25)
[sub_resource type="TorusMesh" id="TorusMesh_llm6e"]
inner_radius = 0.75
outer_radius = 0.8
rings = 20
ring_segments = 6
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jq1ic"]
emission_enabled = true
emission = Color(0, 1, 1, 1)
emission_energy_multiplier = 3.0
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_llm6e"]
height = 1.0
[sub_resource type="VoxelGeneratorFlat" id="VoxelGeneratorFlat_llm6e"]
channel = 0
[sub_resource type="VoxelMesherBlocky" id="VoxelMesherBlocky_ofs8c"]
library = ExtResource("1_r886l")
[node name="Robots" type="Node"]
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_5yot8")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(-0.866024, -0.433016, 0.250001, 0, 0.499998, 0.866026, -0.500003, 0.749999, -0.43301, 0, 0, 0)
shadow_enabled = true
[node name="Robot" type="CharacterBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.5, 0.5)
script = ExtResource("1_nnl6p")
[node name="MeshInstance3D" type="MeshInstance3D" parent="Robot"]
mesh = SubResource("BoxMesh_oo1c2")
[node name="MeshInstance3D2" type="MeshInstance3D" parent="Robot"]
transform = Transform3D(-1, 1.50996e-07, -6.60024e-15, 0, -4.37114e-08, -1, -1.50996e-07, -1, 4.37114e-08, 0, 0.50484, -0.3)
mesh = SubResource("PrismMesh_nnl6p")
[node name="indicator" type="Node3D" parent="Robot"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0)
visible = false
[node name="MeshInstance3D3" type="MeshInstance3D" parent="Robot/indicator"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
mesh = SubResource("TorusMesh_llm6e")
skeleton = NodePath("../..")
surface_material_override/0 = SubResource("StandardMaterial3D_jq1ic")
[node name="MeshInstance3D4" type="MeshInstance3D" parent="Robot/indicator"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.8, 0)
mesh = SubResource("TorusMesh_llm6e")
skeleton = NodePath("../..")
surface_material_override/0 = SubResource("StandardMaterial3D_jq1ic")
[node name="MeshInstance3D5" type="MeshInstance3D" parent="Robot/indicator"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2, 0)
mesh = SubResource("TorusMesh_llm6e")
skeleton = NodePath("../..")
surface_material_override/0 = SubResource("StandardMaterial3D_jq1ic")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Robot"]
shape = SubResource("CapsuleShape3D_llm6e")
[node name="VoxelTerrain" type="VoxelTerrain" parent="."]
generator = SubResource("VoxelGeneratorFlat_llm6e")
mesher = SubResource("VoxelMesherBlocky_ofs8c")
bounds = AABB(-1040, -32, -1040, 2080, 96, 2080)
material_override = ExtResource("2_nnl6p")
[node name="TerrainEditor" parent="VoxelTerrain" instance=ExtResource("4_llm6e")]
[node name="ControllableCamera" parent="." instance=ExtResource("1_ecqtg")]
transform = Transform3D(0.97668, -0.143377, 0.159808, 0, 0.744336, 0.667805, -0.214699, -0.652232, 0.726979, 1.39679, 4.07542, 4.92893)
[connection signal="input_event" from="Robot" to="Robot" method="_on_input_event"]

56
nodes/robots/robot.gd Normal file
View File

@@ -0,0 +1,56 @@
extends CharacterBody3D
@onready var terrain := get_node("../VoxelTerrain") as VoxelTerrain
var selected := false
var path : Array[Vector3i]
func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
if event is InputEventMouseButton and event.is_pressed():
var button_event = event as InputEventMouseButton
if button_event.button_index == MOUSE_BUTTON_LEFT:
$indicator.visible = true
selected = true
elif button_event.button_index == MOUSE_BUTTON_RIGHT:
$indicator.visible = false
selected = false
func _unhandled_input(event: InputEvent) -> void:
if selected:
if event is InputEventMouseButton and event.is_pressed():
var button_event = event as InputEventMouseButton
if button_event.button_index == MOUSE_BUTTON_LEFT:
move_to_mouse_click()
elif button_event.button_index == MOUSE_BUTTON_RIGHT:
pass
func move_to_mouse_click():
var mouse_pos_2d := get_viewport().get_mouse_position()
var current_camera := get_viewport().get_camera_3d()
var origin := current_camera.project_ray_origin(mouse_pos_2d)
var dir := current_camera.project_ray_normal(mouse_pos_2d)
var res := terrain.get_voxel_tool().raycast(origin, dir, 100)
var path_finder := VoxelAStarGrid3D.new()
path_finder.set_terrain(terrain)
path_finder.set_region(AABB(Vector3.ONE * -100, Vector3.ONE * 200))
path = path_finder.find_path(Vector3i(global_position), res.previous_position)
path.append(res.previous_position)
for step in path:
print(step)
func _process(delta: float) -> void:
if not path.is_empty():
var next_position := Vector3(path[0]) + Vector3.ONE * 0.5;
if path.size() == 1:
if next_position.distance_to(global_position) < 0.1:
rotation.x = 0
rotation.y = round(rotation.y/(PI/2))*PI/2
rotation.z = 0
print("arrived")
if next_position.distance_to(global_position) < 0.1:
global_position = next_position
path.remove_at(0)
else:
look_at(next_position)
velocity = (next_position - global_position).normalized() * 5
move_and_slide()

View File

@@ -0,0 +1 @@
uid://bnw0h8cuyf3g5