void Update() { tc.leftMove = Input.GetAxis("Forward1"); tc.rightMove = Input.GetAxis("Forward2"); tc.leftBrake = Input.GetKey(KeyCode.Space) && Input.GetAxisRaw("Forward1") == 0; tc.rightBrake = Input.GetKey(KeyCode.Space) && Input.GetAxisRaw("Forward2") == 0; if (Input.GetMouseButton(0) || Input.GetKey(KeyCode.A)) { tc.TryFire(); } Ray ray = new Ray(aimRef.position, aimRef.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1000, 1 << 10)) { tc.turrentTarget = hit.point; } else { tc.turrentTarget = ray.origin + 1000 * ray.direction; } if (tc.Predict(0.4f, 6, out predictionHit, out prediction)) { hasPrediction = true; } }
void Update() { if (!tc.isDestroyed) { refindTimer -= Time.deltaTime; TankControl hitTC; Vector3 hitpoint; tc.Predict(0.5f, 4, out hitTC, out hitpoint); if (attackTarget && !attackTarget.isDestroyed) { pf.UpdateTarget(attackTarget.transform.position); tc.turrentTarget = tc.CalculateAim(attackTarget.transform.position); if (hitTC == attackTarget) { tc.TryFire(); } var distance = (attackTarget.transform.position - transform.position).magnitude; targetDir = pf.GetVelocityDir(transform.position); targetVel = Mathf.Clamp((distance - 30) / 1.5f, 0, 80 / 3.6f); } else if (captureTarget) { pf.UpdateTarget(captureTarget.transform.position); var distance = (captureTarget.transform.position - transform.position).magnitude; targetDir = pf.GetVelocityDir(transform.position); targetVel = Mathf.Clamp((distance - 5) / 1.5f, 0, 80 / 3.6f); } else { targetVel = 0; } MoveTowardVel(targetDir * targetVel); } }