mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 11:52:40 +01:00
Make forward direction part of character state to simplify
This allows activities to make the final call about what direction a character should be facing based on the direction they want to be looking.
This commit is contained in:
parent
0d2e34ab58
commit
478cbf6187
@ -105,6 +105,7 @@ public:
|
||||
CharacterObject* getCharacter() const;
|
||||
|
||||
void setMoveDirection(const glm::vec3& movement);
|
||||
void setLookDirection(const glm::vec2& look);
|
||||
|
||||
void setRunning(bool run);
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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) ) {
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user