# Moving a player rectangle smoothly

**URL:** <https://discourse.processing.org/t/moving-a-player-rectangle-smoothly/22763>\
**Category:** Coding Questions\
**Created:** [July 21, 2020, 5:40pm UTC](https://discourse.processing.org/t/moving-a-player-rectangle-smoothly/22763 "2020-07-21T17:40:26Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)\
**Post date:** [July 21, 2020, 10:18pm UTC](https://discourse.processing.org/t/moving-a-player-rectangle-smoothly/22763/4 "2020-07-21T22:18:03Z")

</div>

> [@Smooth Moving code](https://discourse.processing.org/t/smooth-moving-code/7126/4):
>
> Here, your code adjusted to move the square around smoothly. float x = 100; float y = 100; float xSpeed = 0; float ySpeed = 0; boolean keyLeft, keyRight, keyUp, keyDown; void setup() { size(600, 400); } void draw() { background(0); rect(x, y, 10, 10); countSpeed(); //Change speed based on current keys pressed. changePosition(); //Change position based on speed. xSpeed \*= 0.9; //Apply some drag so that the square wouldn't fly off the screen indefinitely ySpeed \*= 0.9…

You can search on google “processing smooth character movement” to find more similar posts.  
The code in this post worked great for me.

---

_[View the full topic](https://discourse.processing.org/t/moving-a-player-rectangle-smoothly/22763)._
