HurtboxBase can now find a character hit solely from the CharacterSkeleton3D.
This commit is contained in:
@@ -55,47 +55,47 @@ void HurtboxBase::_ready()
|
|||||||
|
|
||||||
void HurtboxBase::_physics_process(double delta)
|
void HurtboxBase::_physics_process(double delta)
|
||||||
{
|
{
|
||||||
TypedArray<Character3D> characters_hit_this_frame;
|
|
||||||
|
|
||||||
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
|
const TypedArray<Node3D> &bodies = this->get_overlapping_bodies();
|
||||||
const uint32_t num_bodies = bodies.size();
|
const uint32_t num_bodies = bodies.size();
|
||||||
|
|
||||||
for (uint32_t i = 0; i < num_bodies; i++)
|
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);
|
Character3D *body = cast_to<Character3D>(character_skeleton->get_parent());
|
||||||
TypedArray<int32_t> bone_hits;
|
if (body && !this->hit_character_bodies.has(body))
|
||||||
|
|
||||||
for (uint32_t bone_index = 0; bone_index < num_bodies; bone_index++)
|
|
||||||
{
|
{
|
||||||
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());
|
if (String(bone->get_path()).begins_with(String(body->get_path())))
|
||||||
PRINT_LOG(HURTBOX_BASE_TAG, "Bone hit: ", bone->get_name(), " (", bone->get_class(), " : ", bone->get_rid(), ")");
|
{
|
||||||
|
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)
|
if (this->remaining_life <= 0.0f)
|
||||||
this->collision_shape->set_disabled(true);
|
this->collision_shape->set_disabled(true);
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user