# Constrain() player movement not working

**URL:** <https://discourse.processing.org/t/constrain-player-movement-not-working/10199>\
**Category:** Processing.py\
**Created:** [April 11, 2019, 9:56pm UTC](https://discourse.processing.org/t/constrain-player-movement-not-working/10199 "2019-04-11T21:56:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sky](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sky/32/3013_2.png) [@Sky](https://discourse.processing.org/u/Sky)\
**Post date:** [April 11, 2019, 9:56pm UTC](https://discourse.processing.org/t/constrain-player-movement-not-working/10199/1 "2019-04-11T21:56:48Z")

</div>

```auto
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

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [April 11, 2019, 10:29pm UTC](https://discourse.processing.org/t/constrain-player-movement-not-working/10199/2 "2019-04-11T22:29:18Z")

</div>

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

> [@Player movement laggy](https://discourse.processing.org/t/player-movement-laggy/7366/2):
>
> Inspired by my old Java Mode “Player Move”: coffee[Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp](http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp) I’ve made a Python Mode version “Paddle Move”:snake """ Paddle Move (v1.0.2) by GoToLoop (2019-Jan-09) https://Discourse.Processing.org/t/player-movement-laggy/7366/2 http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp """ BG = 0350 def setup(): size(800, 600) colorMode(RGB) rectMode(CORNER) fill(Paddle.INK) stroke(Paddle.OUTLINE) …

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [April 12, 2019, 12:05am UTC](https://discourse.processing.org/t/constrain-player-movement-not-working/10199/3 "2019-04-12T00:05:05Z")

</div>

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

```auto
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)

```
