// Update is called once per frame void FixedUpdate() { float motor = carJoystick.Vertical; float steering = carJoystick.Horizontal; float breaks = 0; if (Mathf.Abs(motor) < .2f) { breaks = 1; } car.MoveCar(motor, steering, breaks); cannon.RotateCannon(cannonJoystick.Horizontal); cannon.ElevateCannon(-cannonJoystick.Vertical); }
private void RotateCannon() { if (distanceToTarget > maxShootingDistance) { return; } Transform cannon = cannonControl.CannonBase().transform; Vector3 cannonDirection = (targetPosition - cannon.position).normalized; float rotation = Vector3.Dot(cannon.right, cannonDirection) * 10; cannonControl.RotateCannon(rotation); if (Mathf.Abs(rotation) < .15f) { shooter.Shoot(); } }