private void FireShot(GunSettings gunSettings)
        {
            var ray = shotRayProvider.GetShotRay(gunState.Data.IsAiming, camera);

            shooting.FireShot(gunSettings.ShotRange, ray);
            shooting.InitiateCooldown(gunSettings.ShotCooldown);
        }
Esempio n. 2
0
    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 FireShot(GunSettings gunSettings)
        {
            Transform tmp  = null;
            var       ray  = shotRayProvider.GetShotRay(gunState.Data.IsAiming, camera);
            var       info = shooting.FireShot(gunSettings.ShotRange, ray, out tmp);

            shooting.InitiateCooldown(gunSettings.ShotCooldown);

            shootingWriter.SendShotsEvent(info);
        }
Esempio n. 4
0
    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);
            }
        }
    }