# \[SOLVED\] Diagonal Movement

**URL:** <https://discourse.processing.org/t/solved-diagonal-movement/6978>\
**Category:** Processing.py\
**Created:** [December 29, 2018, 10:41am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978 "2018-12-29T10:41:09Z")\
**Posts on this page:** 6\
**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:** [December 29, 2018, 10:41am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978/1 "2018-12-29T10:41:09Z")

</div>

🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

Hello again, now that I made this account I need to use it 😉

```auto
1. def keyPressed(self):
2. if key == 'a':
3. self.x = self.x - 1.5
4. elif key == 'd':
5. self.x = self.x + 1.5
6. elif key == 's':
7. self.y = self.y + 1.5
8. elif key == 'w':
9. self.y = self.y - 1.5

```

Is there any way to make my player object move in diagonal by adjusting something in this code, or I need to do something complex with tan() cos() sin()… ?

🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍🐍

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 29, 2018, 11:16am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978/2 "2018-12-29T11:16:24Z")

</div>

how about using key q e z c  
and do a ± “speed” for X and Y

---

<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:** [December 29, 2018, 11:19am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978/3 "2018-12-29T11:19:36Z")

</div>

Id like to move in diagonal with WD WA…, but this is a good idea too.  
(Actually I’m making things for fun, so I dont need something compelx or very efficient)  
😃

---

<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:** [December 29, 2018, 11:20am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978/4 "2018-12-29T11:20:15Z")

</div>

Here’s some old sketch about diagonal movement, but in Java Mode: ☕  
[Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp](http://Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp)

I can convert it to Python Mode if you wish… 🐍

---

<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:** [December 29, 2018, 11:26am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978/5 "2018-12-29T11:26:30Z")

</div>

@GoToLoop I dont understant what d\>\>1 is (“81. int r = **d\>\>1** ”)  
I’ve never seen something like this in C++ or Python

---

<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:** [December 29, 2018, 11:30am UTC](https://discourse.processing.org/t/solved-diagonal-movement/6978/6 "2018-12-29T11:30:56Z")

</div>

> [@Sky](#):
>
> I’ve never seen something like this in C++ or Python.

> **[\>\> (right shift) \\ Language (API)](https://py.processing.org/reference/rightshift.html)**
>
> Python Mode for Processing extends the Processing Development Environment with the Python programming language.
