From 0b2ac30529c69b9ee163aedb1d4757f70c1a683f Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Sun, 29 Sep 2019 18:31:06 +0200 Subject: [PATCH 1/2] Improve player vehicle exit logic The player can now no longer accelerate whilst exiting a vehicle. This prevents Claude from floating next to the vehicle if the player accelerates during the exit animation. --- rwengine/src/ai/CharacterController.cpp | 3 +++ rwengine/src/objects/VehicleObject.cpp | 2 +- rwgame/states/IngameState.cpp | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/rwengine/src/ai/CharacterController.cpp b/rwengine/src/ai/CharacterController.cpp index 99780adc4..608e32a3a 100644 --- a/rwengine/src/ai/CharacterController.cpp +++ b/rwengine/src/ai/CharacterController.cpp @@ -505,6 +505,9 @@ bool Activities::EnterVehicle::update(CharacterObject *character, bool Activities::ExitVehicle::update(CharacterObject *character, CharacterController *controller) { + /// @todo Acitivty must be cancelled if the player lets go of the + /// the enter/exit vehicle key and the exit animation has not yet + /// started. RW_UNUSED(controller); if (jacked) { diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index a43748094..d036bbb55 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -726,7 +726,7 @@ void VehicleObject::setOccupant(size_t seat, GameObject* occupant) { } bool VehicleObject::canOccupantExit() const { - return getVelocity() <= kVehicleMaxExitVelocity; + return abs(getVelocity()) <= kVehicleMaxExitVelocity; } bool VehicleObject::isOccupantDriver(size_t seat) const { diff --git a/rwgame/states/IngameState.cpp b/rwgame/states/IngameState.cpp index ed2b92846..074257f24 100644 --- a/rwgame/states/IngameState.cpp +++ b/rwgame/states/IngameState.cpp @@ -259,7 +259,7 @@ void IngameState::tick(float dt) { } else if (glm::length2(movement) > 0.001f) { if (player->isCurrentActivity( ai::Activities::EnterVehicle::ActivityName)) { - // Give up entering a vehicle if we're alreadying doing so + // Give up entering a vehicle if we're already doing so player->skipActivity(); } } @@ -267,6 +267,16 @@ void IngameState::tick(float dt) { if (player->getCharacter()->getCurrentVehicle()) { auto vehicle = player->getCharacter()->getCurrentVehicle(); vehicle->setHandbraking(held(GameInputState::Handbrake)); + if (player->isCurrentActivity( + ai::Activities::ExitVehicle::ActivityName)) { + // The player cannot accelerate while exiting. + // He can, however, brake in the opposite direction of movement. + int velocitySign = vehicle->getVelocity() >= 0 ? 1 : -1; + int movementSign = movement.x >= 0 ? 1 : -1; + if (velocitySign == movementSign) { + movement.x = 0; + } + } player->setMoveDirection(movement); } else { if (pressed(GameInputState::Jump)) { From db1c405a18c2d9eaeb797980866ec51f5c57b208 Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Sun, 27 Oct 2019 09:44:12 +0100 Subject: [PATCH 2/2] Replace tabs with spaces --- rwgame/states/IngameState.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rwgame/states/IngameState.cpp b/rwgame/states/IngameState.cpp index 074257f24..a351918ac 100644 --- a/rwgame/states/IngameState.cpp +++ b/rwgame/states/IngameState.cpp @@ -272,10 +272,10 @@ void IngameState::tick(float dt) { // The player cannot accelerate while exiting. // He can, however, brake in the opposite direction of movement. int velocitySign = vehicle->getVelocity() >= 0 ? 1 : -1; - int movementSign = movement.x >= 0 ? 1 : -1; - if (velocitySign == movementSign) { - movement.x = 0; - } + int movementSign = movement.x >= 0 ? 1 : -1; + if (velocitySign == movementSign) { + movement.x = 0; + } } player->setMoveDirection(movement); } else {