am i bad at math or am i bad at javascript

function control_loop() {
    if (controller.dx() > 0) {
        if (x_vel > 40) {
            x_vel = 40
        } else {
            x_vel += 10
        }
    } else if (!(controller.dx() < 0)) {
        if (x_vel < 0 && x_vel != 0) {
            x_vel -= 10
        }
    }
    
    if (controller.dx() < 0) {
        if (x_vel < -40) {
            x_vel = -40
        } else {
            x_vel -= 10
        }
    } else if (!(controller.dx() > 0)) {
        if (x_vel < 0 && x_vel != 0) {
            x_vel -= 10
        } 
    }
}

for context, this code just checks if you have an arrow key pressed and then it’ll change the x velocity to move the player, but the left movement isn’t working (player’s velocity won’t reset like normal)

comments (single view)

It looks like you should change the last -= to +=, that’d be my guest

Guess*

yep, thank you!

View all comments