diff --git a/src/game/object/area.cpp b/src/game/object/area.cpp index 979e485d..ad692a14 100644 --- a/src/game/object/area.cpp +++ b/src/game/object/area.cpp @@ -581,16 +581,14 @@ void Area::update(float dt) { updateHeartbeat(dt); } -bool Area::moveCreatureTowards(const shared_ptr &creature, const glm::vec2 &dest, bool run, float dt) { - glm::vec3 position(creature->position()); - glm::vec2 delta(dest - glm::vec2(position)); - glm::vec2 dir(glm::normalize(delta)); - +bool Area::moveCreature(const shared_ptr &creature, const glm::vec2 &dir, bool run, float dt) { float facing = -glm::atan(dir.x, dir.y); creature->setFacing(facing); float speed = run ? creature->runSpeed() : creature->walkSpeed(); float speedDt = speed * dt; + + glm::vec3 position(creature->position()); position.x += dir.x * speedDt; position.y += dir.y * speedDt; @@ -613,6 +611,12 @@ bool Area::moveCreatureTowards(const shared_ptr &creature, const glm:: return false; } +bool Area::moveCreatureTowards(const shared_ptr &creature, const glm::vec2 &dest, bool run, float dt) { + glm::vec2 delta(dest - glm::vec2(creature->position())); + glm::vec2 dir(glm::normalize(delta)); + return moveCreature(creature, dir, run, dt); +} + void Area::runSpawnScripts() { for (auto &creature : _objectsByType[ObjectType::Creature]) { static_cast(*creature).runSpawnScript(); diff --git a/src/game/object/area.h b/src/game/object/area.h index b03a73fa..9720d1b1 100644 --- a/src/game/object/area.h +++ b/src/game/object/area.h @@ -74,12 +74,14 @@ public: void destroyObject(const SpatialObject &object); void fill(scene::SceneGraph &sceneGraph); void initCameras(const glm::vec3 &entryPosition, float entryFacing); - bool moveCreatureTowards(const std::shared_ptr &creature, const glm::vec2 &dest, bool run, float dt); void onPartyLeaderMoved(); void startDialog(const std::shared_ptr &object, const std::string &resRef); void update3rdPersonCameraFacing(); void update3rdPersonCameraTarget(); + bool moveCreature(const std::shared_ptr &creature, const glm::vec2 &dir, bool run, float dt); + bool moveCreatureTowards(const std::shared_ptr &creature, const glm::vec2 &dest, bool run, float dt); + bool isUnescapable() const; std::shared_ptr getObjectAt(int x, int y) const; diff --git a/src/game/player.cpp b/src/game/player.cpp index e50d1b02..2d295ad5 100644 --- a/src/game/player.cpp +++ b/src/game/player.cpp @@ -132,11 +132,9 @@ void Player::update(float dt) { if (movement) { actions.clear(); - glm::vec2 dest(partyLeader->position()); - dest.x -= 100.0f * glm::sin(facing); - dest.y += 100.0f * glm::cos(facing); + glm::vec2 dir(glm::normalize(glm::vec2(-glm::sin(facing), glm::cos(facing)))); - if (_area->moveCreatureTowards(partyLeader, dest, true, dt)) { + if (_area->moveCreature(partyLeader, dir, true, dt)) { partyLeader->setMovementType(Creature::MovementType::Run); } } else if (actions.empty()) {