generated from Persson-dev/Godot-Xmake
Collision of zombie body parts completed and different damage added depending on the body part hit
This commit is contained in:
@@ -14,6 +14,8 @@ void Zombie::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_m_PlayerPath", "m_PlayerPath"), &Zombie::set_m_PlayerPath);
|
||||
ClassDB::bind_method(D_METHOD("get_m_PlayerPath"), &Zombie::get_m_PlayerPath);
|
||||
ClassDB::bind_method(D_METHOD("hit_finished"), &Zombie::hit_finished);
|
||||
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_head_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_head_shot_hit);
|
||||
ClassDB::bind_method(D_METHOD("_on_area_3d_a_zombie_body_shot_hit", "m_Health"), &Zombie::_on_area_3d_a_zombie_body_shot_hit);
|
||||
|
||||
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "m_PlayerPath"), "set_m_PlayerPath", "get_m_PlayerPath");
|
||||
}
|
||||
@@ -38,6 +40,10 @@ void Zombie::_ready() {
|
||||
m_StateMachine = Object::cast_to<AnimationNodeStateMachinePlayback>(m_AnimationTree->get("parameters/playback"));
|
||||
DEV_ASSERT(m_StateMachine);
|
||||
this->set_velocity(Vector3(0, 0, 0));
|
||||
m_HeadCollision = Object::cast_to<BoneCollisionShape>(find_child("HeadArea3D"));
|
||||
DEV_ASSERT(m_HeadCollision);
|
||||
m_HeadCollision->connect("a_ZombieHeadShotHit", Callable(this, "_on_area_3d_a_zombie_head_shot_hit"));
|
||||
connect_collision_shapes(m_BodyPartsCollision);
|
||||
}
|
||||
|
||||
void Zombie::_process(float a_Delta) {
|
||||
@@ -82,4 +88,29 @@ void Zombie::hit_finished() {
|
||||
m_Player->hit(dir);
|
||||
}
|
||||
}
|
||||
|
||||
void Zombie::apply_damage(int dam) {
|
||||
m_Health -= dam;
|
||||
if (m_Health <= 0) {
|
||||
queue_free();
|
||||
}
|
||||
}
|
||||
|
||||
void Zombie::_on_area_3d_a_zombie_head_shot_hit(int dam) {
|
||||
apply_damage(dam);
|
||||
}
|
||||
|
||||
void Zombie::_on_area_3d_a_zombie_body_shot_hit(int dam) {
|
||||
apply_damage(dam);
|
||||
}
|
||||
|
||||
void Zombie::connect_collision_shapes(const std::vector<StringName>& body_parts) {
|
||||
for (const StringName& part : body_parts) {
|
||||
StringName area_name = String(part) + "Area3D";
|
||||
BoneCollisionShape* collision_shape = Object::cast_to<BoneCollisionShape>(find_child(area_name));
|
||||
DEV_ASSERT(collision_shape);
|
||||
collision_shape->connect("a_ZombieBodyShotHit", Callable(this, "_on_area_3d_a_zombie_body_shot_hit"));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user