Exemplo n.º 1
0
        public bool ShootIfAimed(PotentialTarget target)
        {
            var shouldShoot = ShouldShoot(target);

            Shoot(shouldShoot);

            return(shouldShoot);
        }
Exemplo n.º 2
0
 public void AutoDetonate(PotentialTarget target)
 {
     if (ShouldDetonate(target))
     {
         Debug.Log(_exploderRigidbody + " is auto-detonating - proximity detonator");
         DetonateNow();
     }
 }
Exemplo n.º 3
0
 public EyeballTurretTurner(Rigidbody thisTurret, Rigidbody turnTable, Transform restTarget, float?projectileSpeed)
 {
     _thisTurret = thisTurret;
     if (restTarget != null)
     {
         _restTarget = new PotentialTarget(restTarget);
     }
     _ball            = turnTable;
     _projectileSpeed = projectileSpeed;
 }
Exemplo n.º 4
0
 public bool ShouldShoot(PotentialTarget target)
 {
     //return true;
     if (target != null && target.TargetRigidbody.transform.IsValid() && _aimingObject.IsValid())
     {
         var angle = Vector3.Angle(_aimingObject.forward, target.TargetRigidbody.position - _aimingObject.position);
         return(angle < _shootAngle);
     }
     return(false);
 }
Exemplo n.º 5
0
        private bool ShouldDetonate(PotentialTarget target)
        {
            if (target == null)
            {
                return(false);
            }

            var distance = target.DistanceToTurret(_exploderRigidbody, _exploderRigidbody.velocity.magnitude);

            Debug.Log("target = " + target.TargetTransform + ", distance = " + distance + ", should detonate = " + (distance <= _detonationDistance));
            return(distance <= _detonationDistance);
        }
 public UnityTurretTurner(Rigidbody thisTurret, Rigidbody turnTable, Rigidbody elevationHub, Transform restTarget, float?projectileSpeed)
 {
     _thisTurret = thisTurret;
     if (restTarget != null)
     {
         _restTarget = new PotentialTarget(restTarget);
     }
     _turnTable         = turnTable;
     _turnTableHinge    = turnTable.GetComponent <HingeJoint>();
     _elevationHub      = elevationHub;
     _elevationHubHinge = elevationHub.GetComponent <HingeJoint>();
     _projectileSpeed   = projectileSpeed;
 }
        public void TurnToTarget(PotentialTarget target)
        {
            if (target != null && target.TargetTransform.IsValid() && _turnTable != null && _elevationHub != null)
            {
                HingeJoint hinge = _turnTable.GetComponent("HingeJoint") as HingeJoint;
                if (hinge != null)
                {
                    //Debug.Log(_thisTurret.name + " Turning to target with named " + target.Target.name + " with score " + target.Score);

                    //Debug.Log("getting location in turn table space");

                    var LocationInTurnTableSpace = target.LocationInTurnTableSpace(_turnTable, _projectileSpeed);

                    TurnToTarget(_turnTableHinge, LocationInTurnTableSpace);

                    //var locationInElevationHubSpace = target.LocationInElevationHubSpace(_thisTurret);
                    var locationInElevationHubSpace = target.LocationInElevationHubSpaceAfterTurnTableTurn(_thisTurret, _turnTable.transform, _elevationHub, _projectileSpeed);

                    TurnToTarget(_elevationHubHinge, locationInElevationHubSpace);

                    var location = target.TargetTransform.position;
                    var relative = target.LocationInTurnTableSpace(_turnTable, _projectileSpeed);

                    JointMotor motor = hinge.motor;
                    motor.force = 30;

                    relative.y           = 0;
                    motor.targetVelocity = relative.normalized.x * 500;
                    motor.freeSpin       = false;
                    hinge.motor          = motor;
                    hinge.useMotor       = true;
                    //Debug.Log(hinge.motor.targetVelocity);
                }
            }
            else
            {
                //Debug.Log(_thisTurret.name + " Turning to null target");
            }
        }
Exemplo n.º 8
0
 public static Vector3 LocationInOtherTransformSpace(this PotentialTarget target, Rigidbody otherTransform, float?projectileSpeed)
 {
     return(target.TargetRigidbody != null?
            target.TargetRigidbody.LocationInOtherTransformSpace(otherTransform, projectileSpeed) :
                target.TargetTransform.LocationInOtherTransformSpace(otherTransform));
 }
Exemplo n.º 9
0
 /// <summary>
 /// Returns the distance to the target from the given Rigidbody.
 /// Returns float.MaxValue if the target or turret Rigidbody is null.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="thisTurret"></param>
 /// <param name="projectileSpeed"></param>
 /// <returns></returns>
 public static float DistanceToTurret(this PotentialTarget target, Transform thisTurret)
 {
     return(target.TargetTransform.DistanceToTurret(thisTurret));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Returns the distance to the target from the given Rigidbody.
 /// Returns float.MaxValue if the target or turret Rigidbody is null.
 /// </summary>
 /// <param name="target"></param>
 /// <param name="thisTurret"></param>
 /// <param name="projectileSpeed"></param>
 /// <returns></returns>
 public static float DistanceToTurret(this PotentialTarget target, Rigidbody thisTurret, float?projectileSpeed)
 {
     return(target.TargetRigidbody != null?
            target.TargetRigidbody.DistanceToTurret(thisTurret, projectileSpeed) :
                target.TargetTransform.DistanceToTurret(thisTurret.transform));
 }
Exemplo n.º 11
0
 public static Vector3 CorrectForVelocity(this PotentialTarget target, Rigidbody baseObject, float?projectileSpeed)
 {
     return(target.TargetRigidbody != null?
            target.TargetRigidbody.CorrectForVelocity(baseObject, projectileSpeed) :
                target.TargetTransform.position);
 }
Exemplo n.º 12
0
 public static Vector3 LocationInAimedSpace(this PotentialTarget target, Rigidbody aimingObject, float?projectileSpeed)
 {
     return(target.TargetRigidbody != null?
            target.TargetRigidbody.LocationInAimedSpace(aimingObject, projectileSpeed) :
                target.TargetTransform.LocationInAimedSpace(aimingObject));
 }
Exemplo n.º 13
0
 public static Vector3 LocationInElevationHubSpaceAfterTurnTableTurn(this PotentialTarget target, Rigidbody thisTurret, Transform turnTable, Rigidbody elevationHub, float?projectileSpeed)
 {
     return(target.TargetRigidbody != null?
            target.TargetRigidbody.LocationInElevationHubSpaceAfterTurnTableTurn(thisTurret, turnTable, elevationHub, projectileSpeed) :
                target.TargetTransform.LocationInElevationHubSpaceAfterTurnTableTurn(thisTurret, turnTable, elevationHub));
 }
Exemplo n.º 14
0
 public static Vector3 LocationInTurnTableSpace(this PotentialTarget target, Rigidbody turnTable, float?projectileSpeed)
 {
     return(target.TargetRigidbody != null?
            target.TargetRigidbody.LocationInTurnTableSpace(turnTable, projectileSpeed) :
                target.TargetTransform.LocationInTurnTableSpace(turnTable));
 }