feat: added basic copbot;fix: debris disappears

This commit is contained in:
Sara Gerretsen 2026-01-08 02:10:17 +01:00
parent 6e8814093e
commit bbf16db8d2
20 changed files with 366 additions and 11 deletions

45
assets/spark.svg Normal file
View file

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="135.46666mm"
height="135.46666mm"
viewBox="0 0 135.46666 135.46666"
version="1.1"
id="svg1"
inkscape:version="1.4.3 (0d15f75042, 2025-12-25)"
sodipodi:docname="spark.svg"
inkscape:export-filename="../project/assets/effects/particle_textures/spark_outline.png"
inkscape:export-xdpi="96"
inkscape:export-ydpi="96"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview1"
pagecolor="#000000"
bordercolor="#999999"
borderopacity="1"
inkscape:showpageshadow="2"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:document-units="mm"
inkscape:zoom="1.3808026"
inkscape:cx="212.19543"
inkscape:cy="296.92876"
inkscape:current-layer="layer1" />
<defs
id="defs1" />
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1">
<path
style="fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:3.465;stroke-linecap:square;stroke-linejoin:miter;stroke-opacity:1;paint-order:stroke markers fill"
d="M 6.3490733,65.197263 32.736408,47.487643 60.186319,58.113415 76.479172,41.11218 113.49228,57.759222 130.84771,49.258605 118.80517,77.239804 84.094308,67.322418 63.196955,95.126524 32.382213,64.843073 Z"
id="path1"
sodipodi:nodetypes="ccccccccccc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -0,0 +1,58 @@
#include "cop_bot.h"
#include "break_utopia/macros.h"
#include "break_utopia/player_body.h"
#include "core/config/engine.h"
void CopBot::_bind_methods() {
BIND_PROPERTY(Variant::FLOAT, speed);
}
void CopBot::ready() {
}
void CopBot::process() {
Vector3 player_position{ PlayerBody::get_singleton()->get_global_position() };
Vector3 current_position{ get_global_position() };
Vector3 difference{ player_position - current_position };
Vector3 velocity{ 0, 0, 0 };
constexpr float detection_distance{ 7. * 7. };
if (difference.length_squared() > detection_distance) {
this->aware_of_player = true;
}
if (this->aware_of_player) {
velocity = difference;
}
if (is_on_floor()) {
difference += get_gravity();
} else {
difference.y = 0;
}
set_velocity(difference.normalized() * this->speed);
Vector3 look_at_position{ (current_position - player_position) + current_position };
look_at({ look_at_position.x, current_position.y, look_at_position.z });
}
void CopBot::physics_process() {
move_and_slide();
}
void CopBot::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (what) {
default:
return;
case NOTIFICATION_READY:
set_process(true);
set_physics_process(true);
ready();
return;
case NOTIFICATION_PROCESS:
process();
return;
case NOTIFICATION_PHYSICS_PROCESS:
physics_process();
return;
}
}

View file

@ -0,0 +1,22 @@
#pragma once
#include "break_utopia/macros.h"
#include "scene/3d/physics/character_body_3d.h"
class CopBot : public CharacterBody3D {
GDCLASS(CopBot, CharacterBody3D);
static void _bind_methods();
void ready();
void process();
void physics_process();
protected:
void _notification(int what);
private:
float speed{ 3.f };
bool aware_of_player{ false };
public:
GET_SET_FNS(float, speed);
};

View file

@ -28,6 +28,7 @@ void PlayerBody::_notification(int what) {
default:
return;
case NOTIFICATION_ENTER_TREE:
singleton = this;
set_process_unhandled_input(true);
set_physics_process(true);
if (!is_ready()) {
@ -45,6 +46,10 @@ void PlayerBody::_notification(int what) {
return;
case NOTIFICATION_PAUSED:
this->movement_input = {};
return;
case NOTIFICATION_EXIT_TREE:
singleton = nullptr;
return;
}
}
@ -62,6 +67,10 @@ void PlayerBody::unhandled_input(Ref<InputEvent> const &what) {
}
}
PlayerBody *PlayerBody::get_singleton() {
return singleton;
}
Vector3 PlayerBody::get_transformed_movement_input() const {
Basis const basis{ get_viewport()->get_camera_3d()->get_global_basis() };
Vector3 forward{ basis.get_column(2) };
@ -70,6 +79,8 @@ Vector3 PlayerBody::get_transformed_movement_input() const {
return forward.normalized() * this->movement_input.y + left.normalized() * this->movement_input.x;
}
PlayerBody *PlayerBody::singleton{ nullptr };
String const CharacterState::sig_state_entered{ "state_entered" };
String const CharacterState::sig_state_exited{ "state_exited" };

View file

@ -15,11 +15,13 @@ protected:
virtual void unhandled_input(Ref<InputEvent> const &what) override;
public:
static PlayerBody *get_singleton();
Vector3 get_transformed_movement_input() const;
private:
Vector2 movement_input{};
class CharacterState *default_state{ nullptr };
static PlayerBody *singleton;
};
class CharacterState : public Node {

View file

@ -1,5 +1,6 @@
#include "register_types.h"
#include "break_utopia/cop_bot.h"
#include "break_utopia/damage_box.h"
#include "break_utopia/destructable_object.h"
#include "break_utopia/hit_box.h"
@ -25,6 +26,7 @@ void initialize_break_utopia_module(ModuleInitializationLevel p_level) {
ClassDB::register_class<PlayerCamera>();
ClassDB::register_class<LevelStatus>();
ClassDB::register_class<DestructableObject>();
ClassDB::register_class<CopBot>();
}
void uninitialize_break_utopia_module(ModuleInitializationLevel p_level) {

View file

@ -0,0 +1,21 @@
[gd_resource type="ShaderMaterial" format=3 uid="uid://ct1ew3ffchshe"]
[ext_resource type="Texture2D" uid="uid://ctniyp87xu00c" path="res://assets/effects/particle_textures/spark_outline.png" id="1_qtf5i"]
[ext_resource type="Shader" uid="uid://dnyve0hyuj8p8" path="res://shaders/dither_effect.gdshader" id="2_02fvp"]
[ext_resource type="Texture2D" uid="uid://bj1f1pw2bv14r" path="res://assets/effects/particle_textures/spark.png" id="3_qtf5i"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_8i1g7"]
transparency = 1
cull_mode = 2
shading_mode = 0
albedo_texture = ExtResource("1_qtf5i")
[resource]
render_priority = 0
next_pass = SubResource("StandardMaterial3D_8i1g7")
shader = ExtResource("2_02fvp")
shader_parameter/albedo = ExtResource("3_qtf5i")
shader_parameter/albedo_color = Color(1, 1, 1, 1)
shader_parameter/dither_count = 989.078
shader_parameter/dither_color = Color(1, 1, 1, 1)
shader_parameter/dither_size = 0.426

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

View file

@ -0,0 +1,41 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bj1f1pw2bv14r"
path.s3tc="res://.godot/imported/spark.png-c70d4fde09fe795c8e0764ab421fe149.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://assets/effects/particle_textures/spark.png"
dest_files=["res://.godot/imported/spark.png-c70d4fde09fe795c8e0764ab421fe149.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -0,0 +1,41 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://ctniyp87xu00c"
path.s3tc="res://.godot/imported/spark_outline.png-49d9a1865d42ea84dff48c97f21649b5.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://assets/effects/particle_textures/spark_outline.png"
dest_files=["res://.godot/imported/spark_outline.png-49d9a1865d42ea84dff48c97f21649b5.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/channel_remap/red=0
process/channel_remap/green=1
process/channel_remap/blue=2
process/channel_remap/alpha=3
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

View file

@ -0,0 +1,60 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://coe4vutm4vgkp"
path="res://.godot/imported/cop_bot.blend-01874feb133edda756059b9c966e0b95.scn"
[deps]
source_file="res://assets/models/props/cop_bot.blend"
dest_files=["res://.godot/imported/cop_bot.blend-01874feb133edda756059b9c966e0b95.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true
nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false
import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={}
blender/nodes/visible=0
blender/nodes/active_collection_only=false
blender/nodes/punctual_lights=true
blender/nodes/cameras=true
blender/nodes/custom_properties=true
blender/nodes/modifiers=1
blender/meshes/colors=false
blender/meshes/uvs=true
blender/meshes/normals=true
blender/meshes/export_geometry_nodes_instances=false
blender/meshes/gpu_instances=false
blender/meshes/tangents=true
blender/meshes/skins=2
blender/meshes/export_bones_deforming_mesh_only=false
blender/materials/unpack_enabled=true
blender/materials/export_materials=1
blender/animation/limit_playback=true
blender/animation/always_sample=true
blender/animation/group_tracks=true
gltf/naming_version=2

View file

@ -11,6 +11,8 @@
[sub_resource type="GDScript" id="GDScript_v3jse"]
script/source = "extends Node3D
var count : int = 0
func _ready():
$ImpactFlash2.restart()
await PlayerCamera.get_instance().impact_effect($ImpactFlash2.process_material.color, 0.1, 0.0, 0.02).timeout
@ -22,6 +24,9 @@ func iter(node):
if child is RigidBody3D:
child.linear_velocity = ((child.global_position - global_position).normalized() + Vector3(1, 0 ,0).rotated(Vector3.UP, randf_range(0, PI*2)).normalized()) * 4
child.angular_velocity = Vector3(randf_range(4, 5), randf_range(4, 5), randf_range(4, 5))
count += 1
if count % 3 != 0:
get_tree().create_timer(5 + (count % 5)).timeout.connect(child.queue_free)
iter(child)
"

View file

@ -26,7 +26,7 @@ destroyed_object = ExtResource("2_vdgxb")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.3798828, 0)
shape = SubResource("BoxShape3D_x018o")
[node name="AnimationPlayer" parent="." index="5" unique_id=738202493]
[node name="AnimationPlayer" parent="." index="5" unique_id=83015350]
script = SubResource("GDScript_vdgxb")
[node name="Sprite3D" type="Sprite3D" parent="." index="6" unique_id=1383786363]

View file

@ -0,0 +1,41 @@
[gd_scene format=3 uid="uid://dvb6sye4mtl5b"]
[ext_resource type="PackedScene" uid="uid://coe4vutm4vgkp" path="res://assets/models/props/cop_bot.blend" id="1_i4ydo"]
[ext_resource type="Material" uid="uid://ct1ew3ffchshe" path="res://assets/effects/particle_materials/spark_dithered.tres" id="1_t6o0h"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_t6o0h"]
radius = 0.37841797
height = 1.6645508
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_t6o0h"]
particle_flag_rotate_y = true
emission_shape = 3
emission_box_extents = Vector3(0.01, 0.001, 0.05)
angle_min = -720.0
angle_max = 1.0728835e-05
gravity = Vector3(0, 0, 0)
scale_min = 0.14999999
scale_max = 0.14999999
color = Color(0.14999998, 0.67416656, 1, 1)
[sub_resource type="QuadMesh" id="QuadMesh_i4ydo"]
material = ExtResource("1_t6o0h")
[node name="CopBot" type="CopBot" unique_id=66926075]
collision_layer = 10
collision_mask = 11
[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=503308426]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.16772461, 0)
shape = SubResource("CapsuleShape3D_t6o0h")
[node name="GPUParticles3D" type="GPUParticles3D" parent="CollisionShape3D" unique_id=1732638006]
transform = Transform3D(-0.035157654, -0.9993811, -0.0012136316, 0.9886831, -0.03495849, 0.1458892, -0.14584133, 0.0039292173, 0.98930013, 0.22469312, 0.124421656, 0.84831995)
amount = 2
lifetime = 0.05
local_coords = true
process_material = SubResource("ParticleProcessMaterial_t6o0h")
draw_pass_1 = SubResource("QuadMesh_i4ydo")
[node name="cop_bot" parent="." unique_id=984408595 instance=ExtResource("1_i4ydo")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)

View file

@ -156,6 +156,8 @@ func _ready():
rotate_y(get_parent().global_rotation.y)
func _unhandled_input(event : InputEvent) -> void:
if not $PlayerCamera.current:
return
if event.is_action(\"look_left\") or event.is_action(\"look_right\"):
camera.x = Input.get_axis(\"look_right\", \"look_left\")
elif event.is_action(\"look_up\") or event.is_action(\"look_down\"):
@ -200,7 +202,7 @@ anim_player = NodePath("../character/AnimationPlayer")
[node name="character" parent="." unique_id=2009779628 instance=ExtResource("1_yaurm")]
[node name="BoneAttachment3D" type="BoneAttachment3D" parent="character/character2/Skeleton3D" parent_id_path=PackedInt32Array(2009779628, 491272152) index="2" unique_id=566409344]
[node name="BoneAttachment3D" type="BoneAttachment3D" parent="character/character2/Skeleton3D" parent_id_path=PackedInt32Array(2009779628, 180340569) index="2" unique_id=566409344]
transform = Transform3D(-0.74619925, -0.6650274, 0.030413395, 0.6645052, -0.7468186, -0.026356531, 0.040241107, 0.0005426332, 0.99918985, 0.6361852, 2.0346472, -0.14206453)
bone_name = "hammer_2"
bone_idx = 18

View file

@ -10,6 +10,7 @@
[ext_resource type="PackedScene" uid="uid://bw4dstm6d5s20" path="res://objects/destructable_props/cubicle.tscn" id="6_qcd3b"]
[ext_resource type="PackedScene" uid="uid://dj8ahau6dm3cq" path="res://objects/destructable_props/elevator_door.tscn" id="9_7gix3"]
[ext_resource type="PackedScene" uid="uid://demib6met2202" path="res://assets/models/props/window.blend" id="10_4asn1"]
[ext_resource type="PackedScene" uid="uid://dvb6sye4mtl5b" path="res://objects/enemies/cop_bot.tscn" id="11_dw7u0"]
[sub_resource type="GDScript" id="GDScript_7gix3"]
resource_name = "SwitchableCamera"
@ -76,17 +77,17 @@ collision_layer = 0
collision_mask = 9
[node name="Camera3D" type="Camera3D" parent="FixedCameraArea" unique_id=365299470]
transform = Transform3D(-0.49999994, 0.5046125, -0.7038228, -5.9604645e-08, 0.8127044, 0.5826763, 0.8660255, 0.2913381, -0.4063521, -2.3477, 3.547047, -4.012157)
transform = Transform3D(-0.49999994, 0.5046125, -0.7038227, -5.9604645e-08, 0.8127044, 0.5826763, 0.8660255, 0.29133815, -0.40635207, -2.3477, 2.4325273, -4.012157)
current = true
fov = 82.33703
script = SubResource("GDScript_7gix3")
[node name="CollisionShape3D" type="CollisionShape3D" parent="FixedCameraArea" unique_id=2137745917]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.23052979, 1.3192749, 0.37756348)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.23052979, 1.3192749, 1.4483081)
shape = SubResource("BoxShape3D_4asn1")
[node name="PlayerBody" parent="." unique_id=62983514 instance=ExtResource("1_2venv")]
transform = Transform3D(-1, 0, -8.742279e-08, 0, 1, 0, 8.742279e-08, 0, -1, -7.7382164, -0.048736453, -4.079642)
transform = Transform3D(-1, 0, -8.742279e-08, 0, 1, 0, 8.742279e-08, 0, -1, -7.7382164, -0.048736453, -2.8052344)
[node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=1393410866]
environment = SubResource("Environment_j6w7d")
@ -209,9 +210,9 @@ size = Vector3(53.125366, 3.722519, 51.28418)
material = SubResource("StandardMaterial3D_qcd3b")
[node name="CSGBox3D6" type="CSGBox3D" parent="Environment/CSGCombiner3D" unique_id=1678792100]
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -7.670644, 1.2883607, -4.262349)
transform = Transform3D(-4.37114e-08, 0, 1, 0, 1, 0, -1, 0, -4.37114e-08, -7.670644, 1.2883607, -3.667053)
flip_faces = true
size = Vector3(2.2096357, 2.560913, 2.3857422)
size = Vector3(3.400228, 2.560913, 2.3857422)
[node name="CSGCylinder3D" type="CSGCylinder3D" parent="Environment" unique_id=373013645]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.12889, 1.85767, -1.56893)
@ -439,16 +440,19 @@ transform = Transform3D(-1.0000001, 0, 3.556437e-07, 0, 1, 0, -3.556437e-07, 0,
transform = Transform3D(2.07624e-07, 0, 1, 0, 1, 0, -1, 0, 2.07624e-07, 4.74393, 2.38419e-07, -2.32372)
[node name="elevator_door" parent="." unique_id=970339368 instance=ExtResource("9_7gix3")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -7.6773534, 0.007903814, -5.3367023)
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, -7.6773534, 0.007903814, -4.6273966)
[node name="window" parent="." unique_id=966690472 instance=ExtResource("10_4asn1")]
[node name="window" parent="." unique_id=482701527 instance=ExtResource("10_4asn1")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 32.763763, 1.9936173, -10.591042)
[node name="window2" parent="." unique_id=1723450805 instance=ExtResource("10_4asn1")]
[node name="window2" parent="." unique_id=18057764 instance=ExtResource("10_4asn1")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 32.763763, 1.9936173, -7.0151224)
[node name="window3" parent="." unique_id=570741013 instance=ExtResource("10_4asn1")]
[node name="window3" parent="." unique_id=473202925 instance=ExtResource("10_4asn1")]
transform = Transform3D(-4.371139e-08, 0, 1, 0, 1, 0, -1, 0, -4.371139e-08, 32.763763, 1.9936173, -3.5706081)
[node name="CopBot" parent="." unique_id=66926075 instance=ExtResource("11_dw7u0")]
transform = Transform3D(0, 0, -1.0000001, 0, 1, 0, 1.0000001, 0, 0, 7.106211, 1.0152975, 7.118715)
[connection signal="body_entered" from="FixedCameraArea" to="FixedCameraArea" method="_on_body_entered"]
[connection signal="body_exited" from="FixedCameraArea" to="FixedCameraArea" method="_on_body_exited"]