Merge pull request #18 from ctrlVnt/fix-reverse-function

fix reverse on gamepad and mouse controller
pull/22/head
Lunakepio 2024-02-16 17:09:37 +01:00 committed by GitHub
commit e89f666184
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 4 deletions

View File

@ -121,6 +121,12 @@ export const PlayerController = ({
} else if (rightPressed && currentSpeed > 0) {
steeringAngle = -currentSteeringSpeed;
targetXPosition = camMaxOffset;
} else if (rightPressed && currentSpeed < 0) {
steeringAngle = currentSteeringSpeed;
targetXPosition = -camMaxOffset;
} else if (leftPressed && currentSpeed < 0) {
steeringAngle = -currentSteeringSpeed;
targetXPosition = camMaxOffset;
} else {
steeringAngle = 0;
targetXPosition = 0;
@ -182,13 +188,24 @@ export const PlayerController = ({
}
// REVERSING
if (downPressed && currentSpeed < -maxSpeed) {
if (downPressed) {
if (currentSteeringSpeed < MaxSteeringSpeed) {
setCurrentSteeringSpeed(
Math.min(
currentSteeringSpeed + 0.0001 * delta * 144,
MaxSteeringSpeed
)
);
}
}
if (downPressed && currentSpeed <= 0) {
setCurrentSpeed(
Math.max(currentSpeed - acceleration * delta * 144, -maxSpeed)
);
}
// DECELERATING
else if (!upPressed && !downPressed) {
else if (!upPressed) {
if (currentSteeringSpeed > 0) {
setCurrentSteeringSpeed(
Math.max(currentSteeringSpeed - 0.00005 * delta * 144, 0)

View File

@ -165,13 +165,24 @@ export const PlayerControllerGamepad = ({
}
// REVERSING
if (buttonB && currentSpeed < -maxSpeed) {
if (buttonB) {
if (currentSteeringSpeed < MaxSteeringSpeed) {
setCurrentSteeringSpeed(
Math.min(
currentSteeringSpeed + 0.0001 * delta * 144,
MaxSteeringSpeed
)
);
}
}
if (buttonB && currentSpeed <= 0) {
setCurrentSpeed(
Math.max(currentSpeed - acceleration * delta * 144, -maxSpeed)
);
}
// DECELERATING
else if (!buttonA && !buttonB) {
else if (!buttonA) {
if (currentSteeringSpeed > 0) {
setCurrentSteeringSpeed(
Math.max(currentSteeringSpeed - 0.00005 * delta * 144, 0)