 Yeah, hi everybody. This is a request that I get quite often people want to know how to make the space invaders Player move in a more smooth fashion. This also applies to my pong tutorial. So let's get started So I've started here from my space invaders part 2. You can download that I'll put the link down below from get hub And it'll give you an idea now one thing to keep in mind when I made the original space vaders tutorial It was written in Python 2.7. So I'm going to try and run it on Python 3.8 and see what happens and The answer that question is right now nothing And I entered the wrong thing. I don't know why this happens every single time I do this program now But anyway, there we go You saw how it popped up and then I suddenly got an error. So you see here. It says raw input is not defined This is because raw input doesn't exist now in Python 3. It's now just input So that should fix that error. Let's see what happens Okay, so I move right and every time I push the key it moves So what we want to happen is to push it once and have it move smoothly Is one option? Now the other thing I would say here is it's probably actually better Is to change this to turtle dot main loop and see if that works and That does the same thing The other thing is that actually there's been quite a few changes from Python 2 to Python 3 in the turtle module And if you're using like high charm or something like that You've probably gotten some warnings that this doesn't work that doesn't work and That's a problem. So to fix that you see where we up here We set up the screen when and so all you do down here is instead of turtle listen We want the window to listen and then we want win Win and I'm just using WN. I'm gonna test that and see what happens Okay, and so that is still working and you should not be getting any more of those Warnings or errors except you might have to change this to on key press You know, I'm not getting the warnings and errors because I'm using genie And it just doesn't check those types of things. So let's go ahead and try it one more time And it is still working. So now to get to the main point of this video It's gonna require some changes So where we have here players speed Hey, what I'm gonna do is I'm gonna go ahead and set that to zero and then in this whole section here I'm gonna delete that and so what I'm gonna do is I'm gonna say global player speed and then player Player speed equals I'm gonna try three Just for example, actually I should actually make negative three because I'm moving to the left I'll show you why in a second. So what we have to do This is a different type of program you set up You're gonna have a while true loop in your program to keep the game running So what I got to do is I'm going to move the player So I'm gonna say player dot set X to the Player dot X core parentheses. Don't forget the parentheses plus Player speed So let's go ahead and try that Okay, when we start the player speed is zero I'm gonna push the left arrow And you can see how it goes right off the screen. Okay, so Let's go ahead and fix it so that the right works so here's advice I always give my students something's working and you just got to make a little bit of a change copy and paste it so all I got to do here is go ahead and Change that speed to positive three. So let's go ahead and test that notice how I'm testing all the time. So right left rights left And off the screen. So all we got to do is Check for the borders check borders that check Check borders. So if player dot X X core X core Is greater than don't fret the parentheses is greater than I think it was 290 Okay, and what I'll do is I'll say player dot set X to 290 So that's gonna be our limit and I'm say player speed Equal zero and then I can do again. I'm gonna let's go ahead and test it. Just Good practice here. So that's to the right side See if it stops Okay, it's not was a little bit over there. So I might want to change that 290 to Maybe let's try 287 Few pixels. Let's just 285. I don't like that weird number 285 go ahead and try that Okay stops. That's exactly what we want again. I'm gonna go ahead and copy that and Just make the necessary changes now watch this carefully because I'll get a thousand questions about this This is gonna be less than negative 285 and put that to negative 285 Okay, so if we go past the left border Stay it stay at the border and then player speed equals zero. So I got left Stops and I've got Right and it stops and that is our smooth motion Now there's one other thing we could do that you might find interesting. So I'm gonna go ahead and say deaf stop player and I'm gonna say global Player speed I'm gonna say player speed equals zero so What I'm gonna do here is win Dot on key release This only works in Python 3 and above. I won't work in Python 2 I'm gonna say stop player If I release the left arrow Now I also need to do the same thing For the right arrow So what this does instead is when I release the key So if I hold the key down It moves until I let go of the key So I'm holding down the left arrow. Let go of the left arrow hold down hold it up So you can do either style if you don't want It to stop you can just you know not put these lines in or you can comment them out And so without the lines if I push the right arrow it moves until It hits the wall or until I hit a different arrow So that is how you do smooth motion again Thanks to the people that commented and asked this question again. That is weird. I got three different questions this week Our three different people ask the same question. So here is a video on how to do that. I hope it helps Keep on coding subscribe for updates. Appreciate you taking the time. Take care. Bye. Bye You