SPACE SHOOTER 2D
2. Player Input Movement

- Creating & Adding “PlayerControl” script

- setting “speed” variable as public to see in the inspector
- In “Update()”
- set horizontal & vertical input by using Input.GetAxisRaw()
- with Input.GetAxisRaw(), the values will be -1, 0 or 1
- with the two inputs, make “direction”
- by adding “.normalize”, make a unit vector
- add a customized fuction “Move()” to move “Player”
- we need this fuction in “Update()” because “Player”‘s position must be changed and detected every frame
- set horizontal & vertical input by using Input.GetAxisRaw()

- to limit the Filed where “Player” can move, get the screen size by using “Camera.main.ViewportToWorldPoint()”
- ViewPort has a range (0, 0) to (1, 1)

- get the Player’s current position with “transform.position”
- transform.position of the gameObject this script is attached to
- calculate the new position in “currentPosition” variable
- with “speed” variable, we can change the speed of “Player”
- “direction” is the normalized vector2
- “Time.deltaTime” is very important with this, we smooth the movement
- with “speed” variable, we can change the speed of “Player”




- without “Time.deltaTime”, “Player” moves too dynamically