HurtboxBase can now find a character hit solely from the CharacterSkeleton3D.

This commit is contained in:
2026-09-19 02:13:30 -04:00
parent 6642760206
commit 846174f772
+24 -24
View File
@@ -55,47 +55,47 @@ void HurtboxBase::_ready()
void HurtboxBase::_physics_process(double delta)
{
TypedArray<Character3D> characters_hit_this_frame;
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
const uint32_t num_bodies = bodies.size();
for (uint32_t i = 0; i < num_bodies; i++)
{
if (Character3D *body = cast_to<Character3D>(bodies[i]))
if (PhysicalBone3D *character_bone = cast_to<PhysicalBone3D>(bodies[i]))
{
if (!this->hit_character_bodies.has(body))
if (CharacterSkeleton3D *character_skeleton = cast_to<CharacterSkeleton3D>(character_bone->get_owner()))
{
characters_hit_this_frame.append(body);
TypedArray<int32_t> bone_hits;
for (uint32_t bone_index = 0; bone_index < num_bodies; bone_index++)
Character3D *body = cast_to<Character3D>(character_skeleton->get_parent());
if (body && !this->hit_character_bodies.has(body))
{
if (PhysicalBone3D *bone = cast_to<PhysicalBone3D>(bodies[bone_index]))
this->hit_character_bodies.append(body);
TypedArray<int32_t> bone_hits;
for (uint32_t bone_index = 0; bone_index < num_bodies; bone_index++)
{
if (String(bone->get_path()).begins_with(String(body->get_path())))
if (PhysicalBone3D *bone = cast_to<PhysicalBone3D>(bodies[bone_index]))
{
bone_hits.append(bone->get_bone_id());
PRINT_LOG(HURTBOX_BASE_TAG, "Bone hit: ", bone->get_name(), " (", bone->get_class(), " : ", bone->get_rid(), ")");
if (String(bone->get_path()).begins_with(String(body->get_path())))
{
bone_hits.append(bone->get_bone_id());
PRINT_LOG(HURTBOX_BASE_TAG, "Bone hit: ", bone->get_name(), " (", bone->get_class(), " : ", bone->get_rid(), ")");
}
}
}
PRINT_LOG(HURTBOX_BASE_TAG, "Character hit: ", body->get_name(), " (", body->get_class(), " : ", body->get_rid(), ")");
Dictionary hit_data;
hit_data["body"] = body;
hit_data["bone_hits"] = bone_hits;
hit_data["hit_points"] = this->hit_points;
hit_data["hit_transform"] = this->get_global_transform();
this->hit_data_queue.emplace_back(hit_data);
}
PRINT_LOG(HURTBOX_BASE_TAG, "Character hit: ", body->get_name(), " (", body->get_class(), " : ", body->get_rid(), ")");
Dictionary hit_data;
hit_data["body"] = body;
hit_data["bone_hits"] = bone_hits;
hit_data["hit_points"] = this->hit_points;
hit_data["hit_transform"] = this->get_global_transform();
this->hit_data_queue.emplace_back(hit_data);
}
}
}
this->hit_character_bodies.append_array(characters_hit_this_frame);
if (this->remaining_life <= 0.0f)
this->collision_shape->set_disabled(true);
else