This is a joystick engine from my game Alien Invasion: https://scratch.mit.edu/projects/644040015 Feel free to use it and inside there are comments on parts of code to make it easier to understand.