Door player detection

This commit is contained in:
Marco 2025-07-08 14:31:12 +02:00
commit f7334c056b
14 changed files with 1631 additions and 1361 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -15,9 +15,11 @@ dest_files=["res://.godot/imported/Door.gltf-3de6387b5eb4c064fcd58b6ed01f23c9.sc
nodes/root_type="" nodes/root_type=""
nodes/root_name="" nodes/root_name=""
nodes/root_script=null
nodes/apply_root_scale=true nodes/apply_root_scale=true
nodes/root_scale=1.0 nodes/root_scale=1.0
nodes/import_as_skeleton_bones=false nodes/import_as_skeleton_bones=false
nodes/use_name_suffixes=true
nodes/use_node_type_suffixes=true nodes/use_node_type_suffixes=true
meshes/ensure_tangents=true meshes/ensure_tangents=true
meshes/generate_lods=true meshes/generate_lods=true
@ -32,6 +34,9 @@ animation/trimming=false
animation/remove_immutable_tracks=true animation/remove_immutable_tracks=true
animation/import_rest_as_RESET=false animation/import_rest_as_RESET=false
import_script/path="" import_script/path=""
materials/extract=0
materials/extract_format=0
materials/extract_path=""
_subresources={} _subresources={}
gltf/naming_version=1 gltf/naming_version=1
gltf/embedded_image_handling=1 gltf/embedded_image_handling=1

View file

@ -21,6 +21,8 @@ dest_files=["res://.godot/imported/Door_0.png-cc7c03b22f194c939ef0476dd7916f10.c
compress/mode=3 compress/mode=3
compress/high_quality=false compress/high_quality=false
compress/lossy_quality=0.7 compress/lossy_quality=0.7
compress/uastc_level=0
compress/rdo_quality_loss=0.0
compress/hdr_compression=1 compress/hdr_compression=1
compress/normal_map=0 compress/normal_map=0
compress/channel_pack=0 compress/channel_pack=0
@ -28,6 +30,10 @@ mipmaps/generate=true
mipmaps/limit=-1 mipmaps/limit=-1
roughness/mode=0 roughness/mode=0
roughness/src_normal="" 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/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/normal_map_invert_y=false process/normal_map_invert_y=false

File diff suppressed because one or more lines are too long

View file

@ -1,22 +1,34 @@
[gd_scene load_steps=4 format=3 uid="uid://bubtvv3pa06py"] [gd_scene load_steps=5 format=3 uid="uid://bubtvv3pa06py"]
[ext_resource type="PackedScene" uid="uid://b12y0mtx6ibo8" path="res://3D/BlockbenchModels/Door/Door.gltf" id="1_7axon"] [ext_resource type="PackedScene" uid="uid://b12y0mtx6ibo8" path="res://3D/BlockbenchModels/Door/Door.gltf" id="1_7axon"]
[ext_resource type="Script" uid="uid://b5yceosypf3mu" path="res://Scripts/Actors/3D/Door3D.cs" id="1_y1ovr"]
[sub_resource type="AnimationLibrary" id="AnimationLibrary_y1ovr"]
[sub_resource type="BoxShape3D" id="BoxShape3D_7axon"] [sub_resource type="BoxShape3D" id="BoxShape3D_7axon"]
size = Vector3(1.99927, 2.00482, 0.140869) size = Vector3(1.99927, 2.00482, 0.140869)
[node name="Door3d" type="AnimatableBody3D" groups=["Solid"]] [sub_resource type="BoxShape3D" id="BoxShape3D_evf52"]
size = Vector3(0.98187256, 2.0062256, 0.44836426)
[node name="Door3d" type="AnimatableBody3D" node_paths=PackedStringArray("AnimationPlayer") groups=["Solid"]]
collision_layer = 16 collision_layer = 16
script = ExtResource("1_y1ovr")
AnimationPlayer = NodePath("blockbench_export/AnimationPlayer")
[node name="blockbench_export" parent="." instance=ExtResource("1_7axon")] [node name="blockbench_export" parent="." instance=ExtResource("1_7axon")]
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
&"": SubResource("AnimationLibrary_y1ovr")
}
[node name="CollisionShape3D" type="CollisionShape3D" parent="."] [node name="CollisionShape3D" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00500488, 0.00234985, -0.00524902) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00500488, 0.00234985, -0.00524902)
shape = SubResource("BoxShape3D_7axon") shape = SubResource("BoxShape3D_7axon")
[node name="PlayerDetector" type="Area3D" parent="."]
collision_layer = 0
collision_mask = 2
[node name="CollisionShape3D" type="CollisionShape3D" parent="PlayerDetector"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.035308838, 0.0099487305, -0.035583496)
shape = SubResource("BoxShape3D_evf52")
[connection signal="area_entered" from="PlayerDetector" to="." method="OnPlayerDetected"]
[connection signal="area_exited" from="PlayerDetector" to="." method="OnPlayerUndetected"]
[editable path="blockbench_export"]

View file

@ -1,17 +1,19 @@
[gd_scene load_steps=6 format=3 uid="uid://du6hlcoq0iip4"] [gd_scene load_steps=7 format=3 uid="uid://du6hlcoq0iip4"]
[ext_resource type="Script" uid="uid://qxh76ahgexqa" path="res://Scripts/Interactables/Switch3D.cs" id="1_papkq"] [ext_resource type="Script" uid="uid://qxh76ahgexqa" path="res://Scripts/Interactables/Switch3D.cs" id="1_papkq"]
[ext_resource type="Texture2D" uid="uid://d24g1qb40t72l" path="res://Sprites/Button_Small.png" id="2_ldivl"] [ext_resource type="Texture2D" uid="uid://d24g1qb40t72l" path="res://Sprites/Button_Small.png" id="2_ldivl"]
[ext_resource type="AudioStream" uid="uid://bjvklk7qmlivd" path="res://SFX/288963__littlerobotsoundfactory__click_electronic_14.wav" id="3_ldivl"] [ext_resource type="AudioStream" uid="uid://bjvklk7qmlivd" path="res://SFX/288963__littlerobotsoundfactory__click_electronic_14.wav" id="3_ldivl"]
[ext_resource type="AudioStream" uid="uid://myr6n2c1u503" path="res://SFX/581602__samsterbirdies__beep-error.mp3" id="4_cjle7"]
[ext_resource type="PackedScene" uid="uid://br2jnsx6v707w" path="res://3D/BlockbenchModels/ControlPad/Control_Pad.gltf" id="4_dfw4f"] [ext_resource type="PackedScene" uid="uid://br2jnsx6v707w" path="res://3D/BlockbenchModels/ControlPad/Control_Pad.gltf" id="4_dfw4f"]
[sub_resource type="SphereShape3D" id="SphereShape3D_itd0i"] [sub_resource type="SphereShape3D" id="SphereShape3D_itd0i"]
radius = 0.868968 radius = 0.868968
[node name="ControlPad" type="Area3D" groups=["Interactable"]] [node name="ControlPad" type="Area3D" node_paths=PackedStringArray("Targets") groups=["Interactable"]]
collision_layer = 32 collision_layer = 32
collision_mask = 0 collision_mask = 0
script = ExtResource("1_papkq") script = ExtResource("1_papkq")
Targets = []
metadata/_edit_group_ = true metadata/_edit_group_ = true
[node name="Sprite3D" type="Sprite3D" parent="."] [node name="Sprite3D" type="Sprite3D" parent="."]
@ -26,10 +28,15 @@ hframes = 4
shape = SubResource("SphereShape3D_itd0i") shape = SubResource("SphereShape3D_itd0i")
[node name="ActivationSound" type="AudioStreamPlayer3D" parent="."] [node name="ActivationSound" type="AudioStreamPlayer3D" parent="."]
visible = false transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15351868)
stream = ExtResource("3_ldivl") stream = ExtResource("3_ldivl")
bus = &"Effects" bus = &"Effects"
[node name="DenySound" type="AudioStreamPlayer3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -0.15351868)
stream = ExtResource("4_cjle7")
bus = &"Effects"
[node name="blockbench_export" parent="." instance=ExtResource("4_dfw4f")] [node name="blockbench_export" parent="." instance=ExtResource("4_dfw4f")]
[editable path="blockbench_export"] [editable path="blockbench_export"]

View file

@ -0,0 +1,34 @@
[gd_scene load_steps=2 format=3 uid="uid://k2nibnfnab3j"]
[ext_resource type="PackedScene" uid="uid://ec4m3geediis" path="res://IsoTest/IsoMapTest2.tscn" id="1_qvtkl"]
[node name="RenderScene" type="Node2D"]
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="TextureRect" type="TextureRect" parent="CanvasLayer"]
visible = false
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="SubViewportContainer" type="SubViewportContainer" parent="CanvasLayer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="SubViewport" type="SubViewport" parent="CanvasLayer/SubViewportContainer"]
handle_input_locally = false
snap_2d_transforms_to_pixel = true
snap_2d_vertices_to_pixel = true
size = Vector2i(320, 180)
size_2d_override = Vector2i(640, 360)
render_target_update_mode = 4
[node name="IsoMapTest2" parent="CanvasLayer/SubViewportContainer/SubViewport" instance=ExtResource("1_qvtkl")]

View file

@ -2,31 +2,19 @@
[ext_resource type="Resource" uid="uid://5bc1qysixhmh" path="res://3D/TrenchBroom/EntityDefinitions/base/actor_base.tres" id="1_3puc0"] [ext_resource type="Resource" uid="uid://5bc1qysixhmh" path="res://3D/TrenchBroom/EntityDefinitions/base/actor_base.tres" id="1_3puc0"]
[ext_resource type="Resource" uid="uid://c1utxplehq2jl" path="res://3D/TrenchBroom/EntityDefinitions/base/targetname_base.tres" id="2_7csyq"] [ext_resource type="Resource" uid="uid://c1utxplehq2jl" path="res://3D/TrenchBroom/EntityDefinitions/base/targetname_base.tres" id="2_7csyq"]
[ext_resource type="PackedScene" uid="uid://c0262d4ffxx1w" path="res://3D/Scenes/Props/Door_Path_3D.tscn" id="3_7csyq"] [ext_resource type="PackedScene" uid="uid://bubtvv3pa06py" path="res://3D/Scenes/Props/Door_3D.tscn" id="3_7csyq"]
[ext_resource type="Script" uid="uid://dkmyelig23ub5" path="res://addons/func_godot/src/fgd/func_godot_fgd_model_point_class.gd" id="3_gqtxh"] [ext_resource type="Script" uid="uid://dkmyelig23ub5" path="res://addons/func_godot/src/fgd/func_godot_fgd_model_point_class.gd" id="3_gqtxh"]
[resource] [resource]
script = ExtResource("3_gqtxh") script = ExtResource("3_gqtxh")
target_map_editor = 1 target_map_editor = 1
models_sub_folder = ""
scale_expression = ""
generate_size_property = false
rotation_offset = Vector3(0, 0, 0)
generate_gd_ignore_file = false
scene_file = ExtResource("3_7csyq") scene_file = ExtResource("3_7csyq")
apply_rotation_on_map_build = true
apply_scale_on_map_build = false apply_scale_on_map_build = false
classname = "actor_door_1" classname = "actor_door_1"
description = "Door Type 1" description = "Door Type 1"
func_godot_internal = false
base_classes = Array[Resource]([ExtResource("1_3puc0"), ExtResource("2_7csyq")]) base_classes = Array[Resource]([ExtResource("1_3puc0"), ExtResource("2_7csyq")])
class_properties = {}
class_property_descriptions = {}
auto_apply_to_matching_node_properties = false
meta_properties = { meta_properties = {
"model": "\"3D/MapModels/actor_door_1.glb\"", "model": "\"3D/MapModels/actor_door_1.glb\"",
"size": AABB(-4, -16, -16, 4, 16, 16) "size": AABB(-4, -16, -16, 4, 16, 16)
} }
node_class = ""
name_property = ""
metadata/_custom_type_script = "uid://c83r7t467hm4m" metadata/_custom_type_script = "uid://c83r7t467hm4m"

View file

@ -63,7 +63,7 @@ script = ExtResource("16_e2nai")
[node name="Camera3D" type="Camera3D" parent="."] [node name="Camera3D" type="Camera3D" parent="."]
physics_interpolation_mode = 1 physics_interpolation_mode = 1
transform = Transform3D(0.707107, -0.5, 0.5, 0, 0.707107, 0.707107, -0.707107, -0.5, 0.5, 26.5146, 7.935, 10.4923) transform = Transform3D(0.7071068, -0.49999994, 0.5000001, 0, 0.70710695, 0.7071067, -0.7071068, -0.49999994, 0.5000001, 83.9836, 7.935, -24.00831)
projection = 1 projection = 1
size = 7.537 size = 7.537
script = ExtResource("1_g4gcm") script = ExtResource("1_g4gcm")

View file

@ -1,7 +1,7 @@
[gd_resource type="Resource" script_class="ShootingPattern3D" load_steps=4 format=3 uid="uid://bmdxhsjh2qla6"] [gd_resource type="Resource" script_class="ShootingPattern3D" load_steps=4 format=3 uid="uid://bmdxhsjh2qla6"]
[ext_resource type="Resource" uid="uid://dl3nq7odtrnum" path="res://Resources/Bullets/Boss/Rumia/Rumia_Red_Chase_Bullet_3D.tres" id="1_5q7h7"] [ext_resource type="Resource" uid="uid://dl3nq7odtrnum" path="res://Resources/Bullets/Boss/Rumia/Rumia_Red_Chase_Bullet_3D.tres" id="1_5q7h7"]
[ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="2_x15n1"] [ext_resource type="Script" uid="uid://b5s5mjuk1rng5" path="res://Scripts/Resources/TimeModifier.cs" id="2_5q7h7"]
[ext_resource type="Script" uid="uid://bxiprx5nwmpnu" path="res://Scripts/AttackPatterns/ShootingPattern3D.cs" id="3_3bs8m"] [ext_resource type="Script" uid="uid://bxiprx5nwmpnu" path="res://Scripts/AttackPatterns/ShootingPattern3D.cs" id="3_3bs8m"]
[resource] [resource]

181
Scripts/Actors/3D/Door3D.cs Normal file
View file

@ -0,0 +1,181 @@
using System;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Actors._3D;
[Tool]
public partial class Door3D : AnimatableBody3D, IActivable
{
[Export] public string GroupName { get; set; }
[Export] public DoorState State { get; set; } = DoorState.Closed;
[Signal] public delegate void OpeningEventHandler();
[Signal] public delegate void ClosingEventHandler();
[Export] public AnimationPlayer AnimationPlayer { get; set; }
[Export] public string OpenAnimationName { get; set; } = "Open";
[Export] public string CloseAnimationName { get; set; } = "Close";
[Export] public string OpenedAnimationName { get; set; } = "Opened";
[Export] public string ClosedAnimationName { get; set; } = "Closed";
private bool _isAnimating = false;
private bool _isPlayerIncollider = false;
private CollisionShape3D _collisionShape;
public override void _Ready()
{
if (Engine.IsEditorHint()) return;
if (!string.IsNullOrWhiteSpace(GroupName))
{
this.AddToGroup(GroupName);
}
_collisionShape = GetNode<CollisionShape3D>("CollisionShape3D");
SyncAnimation();
AnimationPlayer.AnimationFinished += AnimationPlayerOnAnimationFinished;
}
private void SyncAnimation()
{
if (State is DoorState.Closed)
{
AnimationPlayer.Play(ClosedAnimationName);
}
else
{
AnimationPlayer.Play(OpenedAnimationName);
}
}
private void AnimationPlayerOnAnimationFinished(StringName animName)
{
if (Engine.IsEditorHint()) return;
GD.Print($"Animation finished {animName}");
if ((animName == OpenAnimationName || animName == OpenedAnimationName))
{
State = DoorState.Open;
CallDeferred(MethodName.ToggleCollisionDeferred, false);
}
else if (animName == CloseAnimationName || animName == ClosedAnimationName)
{
State = DoorState.Closed;
CallDeferred(MethodName.ToggleCollisionDeferred, true);
}
_isAnimating = false;
}
public void _func_godot_apply_properties(Dictionary props)
{
GroupName = (string)props["targetname"];
}
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (_isAnimating) return false;
switch (activationType)
{
case ActivationType.Toggle:
case ActivationType.Use:
if (State is DoorState.Open && _isPlayerIncollider)
{
return false;
}
Toggle();
break;
case ActivationType.Enable:
case ActivationType.Close:
if (State is DoorState.Open && _isPlayerIncollider)
{
return false;
}
ChangeState(DoorState.Closed);
break;
case ActivationType.Disable:
case ActivationType.Open:
ChangeState(DoorState.Open);
break;
case ActivationType.Destroy:
break;
default:
throw new ArgumentOutOfRangeException(nameof(activationType), activationType, null);
}
return true;
}
private void ChangeState(DoorState newState)
{
if (_isAnimating) return;
if (State == newState) return;
switch (newState)
{
case DoorState.Open:
AnimationPlayer.Play(OpenAnimationName);
AnimationPlayer.SetSpeedScale(1);
//CallDeferred(MethodName.ToggleCollisionDeferred, false);
break;
case DoorState.Closed:
AnimationPlayer.Play(CloseAnimationName);
AnimationPlayer.SetSpeedScale(1);
//CallDeferred(MethodName.ToggleCollisionDeferred, true);
break;
}
//State = newState;
_isAnimating = true;
}
private void ToggleCollisionDeferred(bool toggle)
{
_collisionShape.Disabled = !toggle;
}
public void Toggle()
{
if (_isAnimating) return;
ChangeState(State is DoorState.Open ? DoorState.Closed : DoorState.Open);
}
public void OnPlayerDetected(Node3D body)
{
_isPlayerIncollider = true;
// if (!_isAnimating) return;
// if (State is DoorState.Open) // It means it's closing
// {
// AnimationPlayer.SetSpeedScale(-1);
// }
}
public void OnPlayerUndetected(Node3D body)
{
_isPlayerIncollider = false;
}
// private bool IsPlayerInArea()
// {
// var spaceState = GetWorld3D().DirectSpaceState;
//
// var query = new PhysicsShapeQueryParameters3D()
// {
// CollideWithBodies = true,
//
// }
//
//
// //query.CollideWithBodies = true;
// }
}

View file

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

View file

@ -13,21 +13,24 @@ public partial class Switch3D : Interactable3D
[Export] public Node Target { get; set; } [Export] public Node Target { get; set; }
[Export] public Array<Node> Targets { get; private set; } = []; [Export] public Array<Node> Targets { get; private set; } = [];
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle; [Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
[Signal] [Signal]
public delegate void OnActivatedEventHandler(ActivationType activationType); public delegate void OnActivatedEventHandler(ActivationType activationType);
private AudioStreamPlayer _activationSound; private AudioStreamPlayer _activationSound;
private AudioStreamPlayer _denySound;
private readonly string _activationSoundName = "ActivationSound"; private readonly string _activationSoundName = "ActivationSound";
private readonly string _denySoundName = "ActivationSound";
public override void _Ready() public override void _Ready()
{ {
if (Engine.IsEditorHint()) return; if (Engine.IsEditorHint()) return;
_activationSound = GetNodeOrNull<AudioStreamPlayer>(_activationSoundName); _activationSound = GetNodeOrNull<AudioStreamPlayer>(_activationSoundName);
_denySound = GetNodeOrNull<AudioStreamPlayer>(_denySoundName);
} }
public void _func_godot_apply_properties(Dictionary<string, string> props) public void _func_godot_apply_properties(Dictionary<string, string> props)
{ {
TargetGroup = props["target"]; TargetGroup = props["target"];
@ -35,6 +38,7 @@ public partial class Switch3D : Interactable3D
{ {
RequirementKeys = [prop]; RequirementKeys = [prop];
} }
if (props.TryGetValue("activationtype", out var type)) if (props.TryGetValue("activationtype", out var type))
{ {
var t = Enum.TryParse(type, true, out ActivationType activationType); var t = Enum.TryParse(type, true, out ActivationType activationType);
@ -46,16 +50,19 @@ public partial class Switch3D : Interactable3D
//TargetFunc = props["targetfunc"]; //TargetFunc = props["targetfunc"];
//TargetName = props["targetname"]; //TargetName = props["targetname"];
} }
public override bool Activate(ActivationType activationType = ActivationType.Toggle) public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{ {
var activationTypeToUse = activationType is ActivationType.Use ? ActivationType : activationType; var activationTypeToUse = activationType is ActivationType.Use ? ActivationType : activationType;
if (!MeetsRequirements()) return false; if (!MeetsRequirements())
_activationSound?.Play(); {
_denySound?.Play();
return false;
}
EmitSignal(SignalName.OnActivated, (int)activationTypeToUse); EmitSignal(SignalName.OnActivated, (int)activationTypeToUse);
// Compatibility for old single system // Compatibility for old single system
bool success = ActivateTarget(Target, activationTypeToUse); bool success = ActivateTarget(Target, activationTypeToUse);
@ -63,8 +70,20 @@ public partial class Switch3D : Interactable3D
{ {
ActivationHelper.UseTargets(this, TargetGroup, activationType); ActivationHelper.UseTargets(this, TargetGroup, activationType);
} }
return Targets.Aggregate(success, (current, target) => ActivateTarget(target, activationTypeToUse) | success); var result = Targets.Aggregate(success,
(current, target) => ActivateTarget(target, activationTypeToUse) | success);
if (result)
{
_activationSound?.Play();
}
else
{
_denySound?.Play();
}
return result;
} }
private bool ActivateTarget(Node target, ActivationType activationType = ActivationType.Toggle) private bool ActivateTarget(Node target, ActivationType activationType = ActivationType.Toggle)
@ -73,7 +92,7 @@ public partial class Switch3D : Interactable3D
activable?.Activate(activationType); activable?.Activate(activationType);
return true; return true;
} }
// private void UseTargets(Node activator, string target) // private void UseTargets(Node activator, string target)
// { // {
// GD.Print($"Trying to use targets called: {target}"); // GD.Print($"Trying to use targets called: {target}");