Commit a0b660a5 authored by Tim Scheiber's avatar Tim Scheiber
Browse files

Added 'follow target' movement behaviour for enemies

parent 6fc1e13c
Pipeline #3247 failed with stage
in 6 minutes and 36 seconds
{
"Transform": {
"scale": {
"x": 0.3,
"y": 0.3,
"z": 0.3
}
},
"Model": {
"aid": "model:cube"
},
"Shadowcaster": {
},
"Movement": {
"beats_per_step": 1,
"distance_per_step": 1,
"step_time_percentage": 0.2,
"off_beat_threshold": 0.2
},
"FollowTarget": {
}
}
......@@ -14,10 +14,10 @@ namespace phase_shifter::gameplay {
void Camera_system::update(mirrage::util::Time dt)
{
for (auto&& [camera, viewtarget, spring] : _entity_manager.list<mirrage::ecs::Entity_facet, Viewtarget_comp, Spring_comp>()) {
auto& target_facet = _entity_manager.get(viewtarget.target);
auto target_facet = _entity_manager.get(viewtarget.target);
if(target_facet.is_some()) {
auto& target_transform = target_facet.get_or_throw().get<mirrage::ecs::components::Transform_comp>();
auto target_transform = target_facet.get_or_throw().get<mirrage::ecs::components::Transform_comp>();
if(target_transform.is_some()) {
auto& target_position = target_transform.get_or_throw().position;
......
#include "enemy_system.hpp"
#include "movement_comp.hpp"
#include <mirrage/ecs/components/transform_comp.hpp>
namespace phase_shifter::gameplay {
Enemy_system::Enemy_system(mirrage::ecs::Entity_manager& entity_manager) : _entity_manager(entity_manager)
{
_entity_manager.register_component_type<Fixed_path_comp>();
_entity_manager.register_component_type<Follow_target_comp>();
}
void Enemy_system::update(mirrage::util::Time dt)
......@@ -21,5 +23,20 @@ namespace phase_shifter::gameplay {
}
}
}
for (auto&&[movement, follow_target, transform] : _entity_manager.list<Movement_comp, Follow_target_comp, mirrage::ecs::components::Transform_comp>()) {
auto target_facet = _entity_manager.get(follow_target.target);
if(target_facet.is_some()) {
auto target_transform = target_facet.get_or_throw().get<mirrage::ecs::components::Transform_comp>();
if(target_transform.is_some()) {
auto& target_position = target_transform.get_or_throw().position;
auto& my_position = transform.position;
movement.aim = glm::vec2({target_position.x - my_position.x, target_position.z - my_position.z});
movement.move = true;
}
}
}
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
#include <mirrage/ecs/entity_manager.hpp>
#include "fixed_path_comp.hpp"
#include "follow_target_comp.hpp"
namespace phase_shifter::gameplay {
......
#pragma once
#include <mirrage/ecs/ecs.hpp>
namespace phase_shifter::gameplay {
struct Follow_target_comp : public mirrage::ecs::Component<Follow_target_comp> {
static constexpr const char* name() { return "FollowTarget"; }
using Component::Component;
mirrage::ecs::Entity_handle target;
};
} // namespace phase_shifter::gameplay
\ No newline at end of file
......@@ -128,6 +128,17 @@ namespace phase_shifter {
});
})
.create();
entities()
.entity_builder("hunting_enemy")
.position({-3, 0, -4})
.post_create([=](ecs::Entity_facet entity) {
entity.process<gameplay::Fixed_path_comp>([&](auto& path) {
path.update_path({90.f, 180.f, 90.f});
});
entity.process([=](gameplay::Follow_target_comp& target) { target.target = playerhandle; });
})
.create();
}
Meta_system::~Meta_system()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment