Exemple #1
0
        // PRIVATE METHODS: ----------------------------------------------------

        private void Update()
        {
            if (this.animator != null && this.useCharge)
            {
                this.animator.SetFloat(ANIM_CHARGE, shooter.GetCharge());
            }
        }
Exemple #2
0
        private TrajectoryRenderer.TrajectoryResult GetTrajectoryResult(CharacterShooter shooter)
        {
            TrajectoryRenderer.Trajectory data = this.trajectory;
            data.layerMask   = this.layerMask;
            data.maxDistance = this.distance;
            data.shooter     = shooter;

            Transform origin = (shooter.muzzle != null
                ? shooter.muzzle.transform
                : shooter.transform
                                );

            return(TrajectoryRenderer.GetTrajectory(
                       origin,
                       data,
                       shooter.GetCharge()
                       ));
        }
Exemple #3
0
        private void ShootProjectile(CharacterShooter shooter, float deviation,
                                     CharacterShooter.ShotType shotType)
        {
            ShootData  shootData = this.GetShootData(shooter);
            GameObject bullet    = null;
            float      velocity  = 1f;

            if (this.aimingMode == AimType.Crosshair || this.aimingMode == AimType.None)
            {
                Vector3 shootPositionA = shootData.originWeapon;
                Vector3 shootPositionB = shootData.destination;

                shootPositionB += this.CalculateError(
                    shooter.gameObject,
                    shootPositionA,
                    shootPositionB,
                    deviation
                    );

                velocity = this.projectileVelocity;

                bullet = PoolManager.Instance.Pick(this.prefabProjectile);
                bullet.transform.SetPositionAndRotation(
                    shootPositionA,
                    Quaternion.LookRotation(shootPositionB - shootPositionA)
                    );
            }
            else if (this.aimingMode == AimType.Trajectory)
            {
                Vector3 shootPositionA = shootData.originWeapon;

                velocity = Mathf.Lerp(
                    this.trajectory.minVelocity,
                    this.trajectory.maxVelocity,
                    shooter.GetCharge()
                    );

                Vector3 shootDirection = shooter.muzzle.GetDirection();

                bullet = PoolManager.Instance.Pick(this.prefabProjectile);
                bullet.transform.SetPositionAndRotation(
                    shootPositionA,
                    Quaternion.LookRotation(shootDirection)
                    );
            }

            if (bullet)
            {
                Rigidbody bulletRB = bullet.GetComponent <Rigidbody>();
                if (bulletRB)
                {
                    Vector3 direction = bullet.transform.TransformDirection(Vector3.forward);
                    bulletRB.velocity        = Vector3.zero;
                    bulletRB.angularVelocity = Vector3.zero;

                    bulletRB.AddForce(direction * velocity, ForceMode.VelocityChange);
                }

                this.ExecuteShootActions(
                    shooter.gameObject,
                    shooter.muzzle.GetPosition(),
                    shooter.muzzle.GetRotation()
                    );
            }
        }