Basic pathfinding working for crying ghosts

This commit is contained in:
2026-01-17 23:37:33 -06:00
parent dd4ce5fcf4
commit 3a63bb6709
46 changed files with 691 additions and 34 deletions

View File

@@ -0,0 +1,72 @@
[gd_resource type="SpriteFrames" load_steps=10 format=3 uid="uid://v2dncd7e66ki"]
[ext_resource type="Texture2D" uid="uid://cktqad5dxfmst" path="res://Characters/Crying Ghost/Sprite-0008.png" id="1_pumse"]
[sub_resource type="AtlasTexture" id="AtlasTexture_3x7sv"]
atlas = ExtResource("1_pumse")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_b8dh6"]
atlas = ExtResource("1_pumse")
region = Rect2(0, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_1m6wj"]
atlas = ExtResource("1_pumse")
region = Rect2(16, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_nxsb8"]
atlas = ExtResource("1_pumse")
region = Rect2(32, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_eav7g"]
atlas = ExtResource("1_pumse")
region = Rect2(48, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_xejkc"]
atlas = ExtResource("1_pumse")
region = Rect2(64, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_xcy63"]
atlas = ExtResource("1_pumse")
region = Rect2(80, 0, 16, 32)
[sub_resource type="AtlasTexture" id="AtlasTexture_uxp54"]
atlas = ExtResource("1_pumse")
region = Rect2(96, 0, 16, 32)
[resource]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_3x7sv")
}],
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_b8dh6")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1m6wj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_nxsb8")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_eav7g")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xejkc")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xcy63")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_uxp54")
}],
"loop": true,
"name": &"idle",
"speed": 5.0
}]

View File

@@ -0,0 +1,38 @@
[gd_scene load_steps=5 format=3 uid="uid://61hp8l06y7ka"]
[ext_resource type="Script" uid="uid://d2mxshuj7um8x" path="res://Characters/Crying Ghost/CryingGhost.cs" id="1_wdx63"]
[ext_resource type="SpriteFrames" uid="uid://v2dncd7e66ki" path="res://Characters/Crying Ghost/Crying Ghost.tres" id="2_6ooq7"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_wdx63"]
radius = 4.0
height = 22.0
[sub_resource type="CircleShape2D" id="CircleShape2D_wdx63"]
radius = 128.0
[node name="CryingGhost" type="CharacterBody2D"]
script = ExtResource("1_wdx63")
Speed = 50.0
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = ExtResource("2_6ooq7")
animation = &"idle"
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CapsuleShape2D_wdx63")
[node name="NavigationAgent2D" type="NavigationAgent2D" parent="."]
path_desired_distance = 4.0
target_desired_distance = 4.0
path_postprocessing = 1
avoidance_enabled = true
radius = 4.0
debug_enabled = true
[node name="DetectionArea" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="DetectionArea"]
shape = SubResource("CircleShape2D_wdx63")
[node name="TargetTimer" type="Timer" parent="."]
wait_time = 0.25

View File

@@ -0,0 +1,78 @@
using Godot;
using System.Diagnostics.CodeAnalysis;
public partial class CryingGhost : CharacterBase
{
private AnimatedSprite2D _animatedSprite = default!;
private NavigationAgent2D _navigationAgent = default!;
private Area2D _detectionArea = default!;
private Timer _targetTimer = default!;
protected Node2D? Target { get; private set; }
[MemberNotNullWhen(true, nameof(Target))]
protected bool HasTarget => Target is not null;
public override void _Ready()
{
_animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
_navigationAgent = GetNode<NavigationAgent2D>("NavigationAgent2D");
_detectionArea = GetNode<Area2D>("DetectionArea");
_targetTimer = GetNode<Timer>("TargetTimer");
_animatedSprite?.Play("idle");
_detectionArea.BodyEntered += OnBodyEntered;
_detectionArea.BodyExited += OnBodyExited;
_targetTimer.Timeout += OnTimeout;
_navigationAgent.VelocityComputed += OnVelocityComputed;
}
public override void _PhysicsProcess(double delta)
{
if (!HasTarget)
{
Velocity = Vector2.Zero;
}
else
{
var nextPosition = _navigationAgent.GetNextPathPosition();
var direction = (nextPosition - GlobalPosition).Normalized();
_navigationAgent.Velocity = direction * Speed;
}
MoveAndSlide();
}
void OnBodyEntered(Node2D body)
{
if (body.IsInGroup("Player"))
{
Target = body;
_navigationAgent.TargetPosition = Target.GlobalPosition;
_targetTimer.Start();
}
}
void OnBodyExited(Node2D body)
{
if (body == Target)
{
Target = null;
_navigationAgent.TargetPosition = GlobalPosition;
_targetTimer.Stop();
}
}
void OnTimeout()
{
if (HasTarget)
{
_navigationAgent.TargetPosition = Target.GlobalPosition;
}
}
void OnVelocityComputed(Vector2 safeVelocity)
{
Velocity = safeVelocity;
}
}

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

View File

@@ -0,0 +1,40 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cktqad5dxfmst"
path="res://.godot/imported/Sprite-0008.png-1fafa4a9bb9b4df1192de33bd2fa3429.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Characters/Crying Ghost/Sprite-0008.png"
dest_files=["res://.godot/imported/Sprite-0008.png-1fafa4a9bb9b4df1192de33bd2fa3429.ctex"]
[params]
compress/mode=0
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=false
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=1