[SOLVED] Diagonal Movement

:snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake:

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

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()… ?

:snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake::snake:

how about using key q e z c
and do a Β± β€œspeed” for X and Y

1 Like

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)
:smiley:

Here’s some old sketch about diagonal movement, but in Java Mode: :coffee:
Studio.ProcessingTogether.com/sp/pad/export/ro.91tcpPtI9LrXp

I can convert it to Python Mode if you wish… :snake:

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

1 Like