← go back

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)

Nov 23, 2023, 5:17 PM
7 0 3

Comments