IEnumerator DefineRotation() { while (true) { Vector3 diff = player.transform.position - transform.position; diff.Normalize(); // delay to rotate in seconds yield return(new WaitForSeconds(turnDelay)); Quaternion toLoc = Quaternion.Euler(MovementFunctions.LookAt2D(transform, diff.x, diff.y)); Quaternion fromLoc = firingArc.rotation; // Speed of rotation while (firingArc.rotation != toLoc) { TurretRotationAnimationAndBulletSpawn(); firingArc.rotation = Quaternion.Lerp(fromLoc, toLoc, Time.time * 0.5f); float angle = Quaternion.Angle(firingArc.rotation, toLoc); // if angle diffence is less than 5 set it to end location to break loop. if (angle < 5) { firingArc.rotation = toLoc; } yield return(null); } yield return(null); } }
private void DefineRotation() { Vector3 diff = player.transform.position - transform.position; diff.Normalize(); firingArc.eulerAngles = MovementFunctions.LookAt2D(transform, diff.x, diff.y); }
// Attacking private void AimAndFireCheck () { if ((InputCapture.hAim > 0.5f || InputCapture.hAim < -0.5f) || (InputCapture.vAim > 0.5f || InputCapture.vAim < -0.5f)) { rotation = MovementFunctions.LookAt2D (transform, InputCapture.hAim, InputCapture.vAim); } firingArc.eulerAngles = rotation; // ATTACKING LEFT ARM if (InputCapture.triggerLeft && !fireLeft) { if (roLo.loadout[2].itemType == ItemType.range && roLo.power[2] > 0) { leftArm.RangedAttack (roLo.loadout[2]); } fireLeft = true; } else if (!InputCapture.triggerLeft) { fireLeft = false; } // ATTACKING RIGHT ARM if (InputCapture.triggerRight && !fireRight) { if (roLo.loadout[3].itemType == ItemType.range && roLo.power[3] > 0) { rightArm.RangedAttack (roLo.loadout[3]); } fireRight = true; } else if (!InputCapture.triggerRight) { fireRight = false; } rightArm.GetComponent<RobotAttack> ().FiringCheck (fireRight); leftArm.GetComponent<RobotAttack> ().FiringCheck (fireLeft); }