Constrain() player movement not working

def keyPressed():
    if key == 'w' or key == 'W':
        player.pos.y == constrain(player.pos.y - player.vel,arena.pos.y,arena.pos.y + arena.h)
    elif key == 's' or key == 'S':
        player.pos.y == constrain(player.pos.y + player.vel,arena.pos.y,arena.pos.y + arena.h)
    if key == 'a' or key == 'A':
        player.pos.x == constrain(player.pos.x - player.vel,arena.pos.x,arena.pos.x + arena.w)
    elif key == 'd' or key == 'D':
        player.pos.x == constrain(player.pos.x + player.vel,arena.pos.x,arena.pos.x + arena.w)

My player doesn’t move, thats all.
Ps.

player.vel = 7

1 Like

I’ve got this “Player Move” sketch from an old post of yours. Maybe it can help you a lil’: :grinning:

2 Likes

atm you’re comparing instead of assigning. change to something like this

def keyPressed():
    if key == 'w' or key == 'W':
        player.pos.y = constrain(player.pos.y - player.vel,arena.pos.y,arena.pos.y + arena.h)
    elif key == 's' or key == 'S':
        player.pos.y = constrain(player.pos.y + player.vel,arena.pos.y,arena.pos.y + arena.h)
    if key == 'a' or key == 'A':
        player.pos.x = constrain(player.pos.x - player.vel,arena.pos.x,arena.pos.x + arena.w)
    elif key == 'd' or key == 'D':
        player.pos.x = constrain(player.pos.x + player.vel,arena.pos.x,arena.pos.x + arena.w)
3 Likes