private void Update_ShootingTarget() { if (TargetIsValid()) { var fudgeFactor = Random.insideUnitSphere * 2f; var gunOrigin = transform.position + Vector3.up; var targetCenter = target.transform.position + Vector3.up + fudgeFactor; var targetRotation = Quaternion.LookRotation(targetCenter - gunOrigin); var rotationAmount = Quaternion.RotateTowards(transform.rotation, targetRotation, 10f); var destination = transform.position + (strafeRight ? transform.right : -transform.right); MoveTowards(destination, MovementSpeed.Run, rotationAmount, false); if (shooting.IsShooting(true) && Mathf.Abs(Quaternion.Angle(targetRotation, transform.rotation)) < 5) { shooting.FireShot(200f, new Ray(gunOrigin, transform.forward)); shooting.InitiateCooldown(0.2f); lastShotTime = Time.time; } if (lastShotTime < Time.time - 10f) { target = null; SetPlayerState(PlayerState.LookingForTarget); } } else { target = null; SetPlayerState(PlayerState.LookingForTarget); } }
private void HandleShooting(bool shootingPressed, bool shootingHeld) { if (shootingPressed) { shooting.BufferShot(); } var isShooting = shooting.IsShooting(shootingHeld); if (isShooting) { FireShot(currentGun.CurrentGunSettings); } }
private void Update_ShootingTarget() { if (!isShooting) { return; } var gunOrigin = transform.position + Vector3.up; var targetCenter = target; var targetRotation = Quaternion.LookRotation(targetCenter - gunOrigin); var rotationAmount = Quaternion.RotateTowards(transform.rotation, targetRotation, 10f); var destination = transform.position; MoveTowards(destination, MovementSpeed.Run, rotationAmount, false); if (shooting.IsShooting(true) && Mathf.Abs(Quaternion.Angle(targetRotation, transform.rotation)) < 5) { Transform tmp = null; var info = shooting.FireShot(200f, new Ray(gunOrigin, transform.forward), out tmp); shooting.InitiateCooldown(0.2f); //士兵不攻击自己人 bool canshot = true; if (tmp != null) { var solider = tmp.GetComponent <SoldierAIServer>(); if (solider != null) { if (soldierDataReader.Data.OwnEntityId == solider.soldierDataReader.Data.OwnEntityId) { canshot = false; } } } if (canshot) { shootingWriter.SendShotsEvent(info); } } }