void GetPlayerInput() { // point the gun where the mouse is (the heading from the PC to the mouse) gunDirection = GameManager.gm.mainCamera.ScreenToWorldPoint(Input.mousePosition) - transform.position; gunDirection.y = 0; gunDirection.Normalize(); turret.forward = gunDirection; // if player is pressing "fire" if (GameManager.gm.inGame && Time.time >= nextShotTime && Input.GetMouseButton(0)) { // fire a shot Ammo _ammo = Instantiate(ammunition, barrel.position, Quaternion.identity); _ammo.AmmoStart(gunDirection); // set cooldown til next shot nextShotTime = Time.time + 1 / rateofFire; if (weaponFlare.isStopped) { weaponFlare.Play(); } } // if player is using the movement keys inputHorizontal = inputVertical = 0; inputHorizontal = Input.GetAxis("Horizontal"); inputVertical = Input.GetAxis("Vertical"); if (inputHorizontal != 0 || inputVertical != 0) { moveDirection.x = inputHorizontal; moveDirection.z = inputVertical; moveDirection.Normalize(); currentSpeed = movementSpeed; stopTimer = 0; // reset timer on input if (thruster.isStopped) { thruster.Play(); } } else { // if no movement input slow down PC stopTimer += Time.deltaTime; currentSpeed = Mathf.Lerp(movementSpeed, 0, stopTimer / timeTilMotionStop); if (thruster.isPlaying) { thruster.Stop(); } } // lerp ship body towards movement direction body.forward = Vector3.Lerp(body.forward, moveDirection, Time.deltaTime * 10); }