diff --git a/rwengine/include/ai/CharacterController.hpp b/rwengine/include/ai/CharacterController.hpp index de277056..c58393cc 100644 --- a/rwengine/include/ai/CharacterController.hpp +++ b/rwengine/include/ai/CharacterController.hpp @@ -105,6 +105,7 @@ public: CharacterObject* getCharacter() const; void setMoveDirection(const glm::vec3& movement); + void setLookDirection(const glm::vec2& look); void setRunning(bool run); diff --git a/rwengine/include/objects/CharacterObject.hpp b/rwengine/include/objects/CharacterObject.hpp index df93a614..89560246 100644 --- a/rwengine/include/objects/CharacterObject.hpp +++ b/rwengine/include/objects/CharacterObject.hpp @@ -101,6 +101,7 @@ private: void destroyActor(); glm::vec3 movement; + glm::vec2 m_look; bool running; bool jumped; @@ -188,6 +189,8 @@ public: void setMovement(const glm::vec3& _m) { movement = _m; } const glm::vec3& getMovement() const { return movement; } + void setLook(const glm::vec2& look) { m_look = look; } + const glm::vec2& getLook() const { return m_look; } /** * @brief playActivityAnimation Plays an animation for an activity. diff --git a/rwengine/src/ai/CharacterController.cpp b/rwengine/src/ai/CharacterController.cpp index 09b41f75..7d538522 100644 --- a/rwengine/src/ai/CharacterController.cpp +++ b/rwengine/src/ai/CharacterController.cpp @@ -116,6 +116,11 @@ void CharacterController::setMoveDirection(const glm::vec3 &movement) character->setMovement(movement); } +void CharacterController::setLookDirection(const glm::vec2 &look) +{ + character->setLook(look); +} + void CharacterController::setRunning(bool run) { character->setRunning(run); @@ -325,6 +330,9 @@ bool Activities::ShootWeapon::update(CharacterObject *character, CharacterContro // Instant hit weapons loop their anim // Thrown projectiles have lob / throw. + // Update player direction + character->setRotation(glm::angleAxis(character->getLook().x, glm::vec3{0.f, 0.f, 1.f})); + if( wepdata->fireType == WeaponData::INSTANT_HIT ) { if( _item->isFiring(character) ) { diff --git a/rwengine/src/objects/CharacterObject.cpp b/rwengine/src/objects/CharacterObject.cpp index d908f50f..e2e72e79 100644 --- a/rwengine/src/objects/CharacterObject.cpp +++ b/rwengine/src/objects/CharacterObject.cpp @@ -314,6 +314,10 @@ void CharacterObject::updateCharacter(float dt) position = getPosition(); + if (canTurn()) { + rotation = glm::angleAxis(m_look.x, glm::vec3{0.f, 0.f, 1.f}); + } + walkDir = rotation * walkDir; if( jumped ) @@ -523,7 +527,7 @@ bool CharacterObject::isOnGround() const bool CharacterObject::canTurn() const { - return isOnGround() && !jumped && isAlive(); + return isOnGround() && !jumped && isAlive() && controller->getCurrentActivity() == nullptr; } void CharacterObject::setJumpSpeed(float speed) diff --git a/rwgame/ingamestate.cpp b/rwgame/ingamestate.cpp index a308f52d..1c522a14 100644 --- a/rwgame/ingamestate.cpp +++ b/rwgame/ingamestate.cpp @@ -271,11 +271,7 @@ void IngameState::tick(float dt) { player->setMoveDirection(glm::vec3(0.f)); } - if (player->getCharacter()->canTurn()) - { - player->getCharacter()->rotation = - glm::angleAxis(movementAngle, glm::vec3(0.f, 0.f, 1.f)); - } + player->setLookDirection({movementAngle, 0.f}); } } else