Skip to content

Commit

Permalink
Fix platformer characters turn back speed when the deceleration is gr…
Browse files Browse the repository at this point in the history
…eater than the acceleration (#6208)
  • Loading branch information
D8H authored Jan 17, 2024
1 parent d0005ba commit c8ebfde
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 0 additions & 1 deletion Extensions/PlatformBehavior/PlatformerObjectBehavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ PlatformerObjectBehavior::GetProperties(
properties["UseLegacyTrajectory"]
.SetLabel(_("Use frame rate dependent trajectories (deprecated, it's "
"recommended to leave this unchecked)"))

.SetGroup(_("Deprecated options"))
.SetDeprecated()
.SetValue(behaviorContent.GetBoolAttribute("useLegacyTrajectory", true)
Expand Down
28 changes: 20 additions & 8 deletions Extensions/PlatformBehavior/platformerobjectruntimebehavior.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace gdjs {
private _yGrabOffset: any;
private _xGrabTolerance: any;

_useLegacyTrajectory: boolean = true;
_useLegacyTrajectory: boolean;

_canGoDownFromJumpthru: boolean = false;

Expand Down Expand Up @@ -355,13 +355,25 @@ namespace gdjs {

private _updateSpeed(timeDelta: float): float {
const previousSpeed = this._currentSpeed;
//Change the speed according to the player's input.
// @ts-ignore
if (this._leftKey) {
this._currentSpeed -= this._acceleration * timeDelta;
}
if (this._rightKey) {
this._currentSpeed += this._acceleration * timeDelta;
// Change the speed according to the player's input.
// TODO Give priority to the last key for faster reaction time.
if (this._leftKey !== this._rightKey) {
if (this._leftKey) {
if (this._currentSpeed <= 0) {
this._currentSpeed -= this._acceleration * timeDelta;
} else {
// Turn back at least as fast as it would stop.
this._currentSpeed -=
Math.max(this._acceleration, this._deceleration) * timeDelta;
}
} else if (this._rightKey) {
if (this._currentSpeed >= 0) {
this._currentSpeed += this._acceleration * timeDelta;
} else {
this._currentSpeed +=
Math.max(this._acceleration, this._deceleration) * timeDelta;
}
}
}

//Take deceleration into account only if no key is pressed.
Expand Down

0 comments on commit c8ebfde

Please sign in to comment.