Slightly more advanced player movement
Today my goal is to get WASD bound to movement of my Player.
So, last I left my Player object, it was sliding endlessly to the side… Though I could control the speed it was sliding, now I want to put the power to move in the fingers of anyone who plays the game.
In Unity, I’m going to go to the Edit menu and select Project Settings, then ‘Input Manager’ to verify the keybinds and the name of the axes I want to use.
Going back to my code, I’m going to assign the horizontal axis to a float value in Update as float HorizontalInput = Input.GetAxis(“Horizontal”); and then slide it into the existing Translate with more multiplications.
Next, I have to do the same for vertical movement! Though I know to be careful and not to simply add in a new float into the existing translate, and also not to just copy and paste the existing lines of code. I want to rewrite the whole line from scratch, to avoid making a mistake and ensure I’m aware of what I’m writing.
I make sure I have transform.Translate(new Vector3(0, 1, 0) * VerticalInput * _speed * Time.deltaTime); which gives me full axes movement within my 2D play space.
That’s it for now, but next time I’ll be setting up player boundaries.