movement: improve code

This commit is contained in:
vis2k 2019-03-17 21:30:38 +01:00
parent a773df4905
commit 6a11335050

View File

@ -16,11 +16,13 @@ void Update()
if (!isLocalPlayer) return; if (!isLocalPlayer) return;
// rotate // rotate
transform.Rotate(0, Input.GetAxis("Horizontal") * rotationSpeed * Time.deltaTime, 0); float horizontal = Input.GetAxis("Horizontal");
transform.Rotate(0, horizontal * rotationSpeed * Time.deltaTime, 0);
// move // move
float vertical = Input.GetAxis("Vertical");
Vector3 forward = transform.TransformDirection(Vector3.forward); Vector3 forward = transform.TransformDirection(Vector3.forward);
agent.velocity = forward * Input.GetAxis("Vertical") * agent.speed; agent.velocity = forward * Mathf.Max(vertical, 0) * agent.speed;
animator.SetBool("Moving", agent.velocity != Vector3.zero); animator.SetBool("Moving", agent.velocity != Vector3.zero);
// shoot // shoot