feat: unit now plays animation on death
This commit is contained in:
		
							parent
							
								
									65b0f76991
								
							
						
					
					
						commit
						d03ce19c13
					
				| 
						 | 
				
			
			@ -19,7 +19,7 @@ void Unit::_enter_tree() { GDGAMEONLY();
 | 
			
		|||
    this->world_state = this->get_node<UnitWorldState>("ActorWorldState");
 | 
			
		||||
    this->eyes = this->get_node<gd::Node3D>("%Eyes");
 | 
			
		||||
    this->world_state->connect("attention_changed", callable_mp(this, &Unit::stop_plan));
 | 
			
		||||
 | 
			
		||||
    this->anim_player = this->get_node<gd::AnimationPlayer>("AnimationPlayer");
 | 
			
		||||
    EntityHealth *health{this->get_node<EntityHealth>("EntityHealth")};
 | 
			
		||||
    health->connect("death", callable_mp(this, &Unit::on_death));
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -77,8 +77,9 @@ void Unit::aim_at(gd::Node3D *target) {
 | 
			
		|||
    this->set_global_basis({x, z.cross(x), z});
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Unit::on_death(Unit *killer) {
 | 
			
		||||
    this->queue_free();
 | 
			
		||||
void Unit::on_death(Unit *damage_source) {
 | 
			
		||||
    this->anim_player->stop();
 | 
			
		||||
    this->anim_player->play("death");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
UnitWorldState *Unit::get_world_state() const {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@
 | 
			
		|||
#include "goap/goal.hpp"
 | 
			
		||||
#include "goap/planner.hpp"
 | 
			
		||||
#include "utils/godot_macros.hpp"
 | 
			
		||||
#include <godot_cpp/classes/animation_player.hpp>
 | 
			
		||||
#include <godot_cpp/classes/character_body3d.hpp>
 | 
			
		||||
#include <godot_cpp/classes/navigation_agent3d.hpp>
 | 
			
		||||
#include <godot_cpp/classes/node3d.hpp>
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +34,7 @@ public:
 | 
			
		|||
 | 
			
		||||
    void fire_at_target();
 | 
			
		||||
    void aim_at(gd::Node3D *node);
 | 
			
		||||
    void on_death(Unit *killer);
 | 
			
		||||
    void on_death(Unit *damage_source);
 | 
			
		||||
 | 
			
		||||
    UnitWorldState *get_world_state() const;
 | 
			
		||||
    gd::Transform3D get_eye_transform() const;
 | 
			
		||||
| 
						 | 
				
			
			@ -60,8 +61,9 @@ private:
 | 
			
		|||
    UnitTeam team{UnitTeam::Neutral};
 | 
			
		||||
 | 
			
		||||
    gd::NavigationAgent3D *agent{nullptr};
 | 
			
		||||
    UnitWorldState *world_state{nullptr};
 | 
			
		||||
    gd::AnimationPlayer *anim_player{nullptr};
 | 
			
		||||
    goap::Planner *planner{nullptr};
 | 
			
		||||
    UnitWorldState *world_state{nullptr};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // !RTS_UNIT_HPP
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue