feat: first basic enemy patrolling behaviour
This commit is contained in:
parent
7c4c75d193
commit
526f756736
15 changed files with 801 additions and 386 deletions
58
modules/wave_survival/enemy_body.cpp
Normal file
58
modules/wave_survival/enemy_body.cpp
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
#include "enemy_body.h"
|
||||
#include "macros.h"
|
||||
#include "npc_unit.h"
|
||||
|
||||
void EnemyBody::_bind_methods() {}
|
||||
|
||||
void EnemyBody::ready() {
|
||||
this->fsm = cast_to<StateMachine>(get_node(NodePath("%StateMachine")));
|
||||
this->nav = cast_to<NavigationAgent3D>(get_node(NodePath("%NavigationAgent3D")));
|
||||
}
|
||||
|
||||
void EnemyBody::physics_process(double delta) {
|
||||
GETSET(velocity, {
|
||||
velocity = Vector3{ this->movement_direction.x, velocity.y, this->movement_direction.y };
|
||||
});
|
||||
move_and_slide();
|
||||
}
|
||||
|
||||
void EnemyBody::_notification(int what) {
|
||||
if (Engine::get_singleton()->is_editor_hint()) {
|
||||
return;
|
||||
}
|
||||
switch (what) {
|
||||
default:
|
||||
return;
|
||||
case NOTIFICATION_READY:
|
||||
set_physics_process(true);
|
||||
ready();
|
||||
return;
|
||||
case NOTIFICATION_PHYSICS_PROCESS:
|
||||
physics_process(get_physics_process_delta_time());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void EnemyBody::set_movement_direction(Vector2 direction) {
|
||||
this->movement_direction = direction;
|
||||
}
|
||||
|
||||
void EnemyBody::set_unit(NpcUnit *unit) {
|
||||
this->unit = unit;
|
||||
}
|
||||
|
||||
NpcUnit *EnemyBody::get_unit() const {
|
||||
return this->unit;
|
||||
}
|
||||
|
||||
NavigationAgent3D *EnemyBody::get_nav() const {
|
||||
return this->nav;
|
||||
}
|
||||
|
||||
void EnemyBody::set_movement_speed(float value) {
|
||||
this->movement_speed = value;
|
||||
}
|
||||
|
||||
float EnemyBody::get_movement_speed() const {
|
||||
return this->movement_speed;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue