Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve player vehicle exit logic #726

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rwengine/src/ai/CharacterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion rwengine/src/objects/VehicleObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@
}

bool VehicleObject::canOccupantExit() const {
return getVelocity() <= kVehicleMaxExitVelocity;
return abs(getVelocity()) <= kVehicleMaxExitVelocity;

Check warning on line 729 in rwengine/src/objects/VehicleObject.cpp

View check run for this annotation

Codecov / codecov/patch

rwengine/src/objects/VehicleObject.cpp#L729

Added line #L729 was not covered by tests
}

bool VehicleObject::isOccupantDriver(size_t seat) const {
Expand Down
12 changes: 11 additions & 1 deletion rwgame/states/IngameState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,24 @@
} 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();
}
}

if (player->getCharacter()->getCurrentVehicle()) {
auto vehicle = player->getCharacter()->getCurrentVehicle();
vehicle->setHandbraking(held(GameInputState::Handbrake));
if (player->isCurrentActivity(
ai::Activities::ExitVehicle::ActivityName)) {

Check warning on line 271 in rwgame/states/IngameState.cpp

View check run for this annotation

Codecov / codecov/patch

rwgame/states/IngameState.cpp#L270-L271

Added lines #L270 - L271 were not covered by tests
// 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;
}
}

Check warning on line 279 in rwgame/states/IngameState.cpp

View check run for this annotation

Codecov / codecov/patch

rwgame/states/IngameState.cpp#L274-L279

Added lines #L274 - L279 were not covered by tests
player->setMoveDirection(movement);
} else {
if (pressed(GameInputState::Jump)) {
Expand Down