// Copyright (c) 2023 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "EntityMove.hpp" using namespace Dawn; EntityMove::EntityMove(SceneItem* item) : SceneItemComponent(item) { } std::vector EntityMove::getDependencies() { return { (characterController = item->getComponent()), (this->entityHealth = item->getComponent()), }; } void EntityMove::onStart() { assertNotNull(this->characterController); assertNotNull(this->entityHealth); useEvent([&](float_t delta) { // Don't move if stunned or attacking. if(entityHealth->isStunned()) return; // Don't move if no move. if(direction.x == 0 && direction.y == 0) return; // Move float_t angle = atan2(direction.y, direction.x); glm::vec2 movement(cosf(angle), sinf(angle)); transform->setLocalRotation(glm::quat(glm::vec3(0, -angle + 1.5708f, 0))); characterController->velocity += movement * delta * moveSpeed; }, getScene()->eventSceneUpdate); }