이전 움직임 코드를 참고하여 조금더 다은 코드로 개선시켜보겠다.
private Rigidbody playerRigidbody;
public float speed = 8f;
void Start()
{
playerRigidbody = GetComponent<Rigidbody>();
}
void Update()
{
float xInput = Input.GetAxis("Horizontal");
float zInput = Input.GetAxis("Vertical");
float xSpeed = xInput * speed;
float zSpeed = zInput * speed;
Vector3 newVelocity = new Vector3(xSpeed, 0f, zSpeed);
playerRigidbody.velocity = newVelocity;
}