Exemple #1
0
    public override void Reaction(GameObject self)
    {
        Vector3       facingDirection = (transform.position - self.transform.position).normalized;
        TankControlAI TCA             = self.GetComponent <TankControlAI>();

        TCA.vertical = Mathf.Abs(self.transform.forward.z) > Mathf.Abs(self.transform.forward.x) ?
                       -(facingDirection.z * self.transform.forward.z) : -(facingDirection.x * self.transform.forward.x);
    }
Exemple #2
0
 // Use this for initialization
 void Start()
 {
     TankConAI     = GetComponent <TankControlAI>();
     TD            = GetComponentInChildren <TurrentDirection>();
     obstacles     = 0;
     Move          = false;
     Aim           = false;
     verticalAngle = 0;
     speed         = 0;
     Fire          = false;
     Anker         = GetComponentInChildren <GimTrim>();
     ammoMass      = GetComponentInChildren <FireAI>().Ammo.GetComponent <Rigidbody>().mass;
 }
Exemple #3
0
    //How the AI tank will react to this obstacle.
    public override void Reaction(GameObject self)
    {
        TankControlAI TCA      = self.GetComponent <TankControlAI>();
        Ray           forward  = new Ray(self.transform.position, self.transform.forward);
        Ray           backward = new Ray(self.transform.position, -self.transform.forward);
        RaycastHit    hitObject;

        if (Physics.SphereCast(forward, 2.0f, out hitObject, 8.0f) || Physics.SphereCast(backward, 2.0f, out hitObject, 8.0f))
        {
            TCA.rotation = 1.0f;
            return;
        }
        TCA.rotation = 0;
    }
Exemple #4
0
    public override void Reaction(GameObject self)
    {
        TankControlAI TCA      = self.GetComponent <TankControlAI>();
        Ray           forward  = new Ray(self.transform.position, self.transform.forward);
        Ray           backward = new Ray(self.transform.position, -self.transform.forward);
        RaycastHit    hitObject;

        if (Physics.SphereCast(forward, 2.0f, out hitObject, 8.0f) || Physics.SphereCast(backward, 2.0f, out hitObject, 8.0f))
        {
            Vector3 difference = hitObject.transform.position - self.transform.position;
            TCA.rotation = Mathf.Abs(self.transform.forward.z) > Mathf.Abs(self.transform.forward.x) ?
                           -(difference.z) * (difference.x) : (difference.x) * (difference.z);
            return;
        }
        TCA.rotation = 0;
    }
Exemple #5
0
    public override void Reaction(GameObject self)
    {
        TankControlAI TCA      = self.GetComponent <TankControlAI>();
        Ray           forward  = new Ray(self.transform.position, self.transform.forward);
        Ray           backward = new Ray(self.transform.position, -self.transform.forward);
        RaycastHit    hitObject;

        //Will command the AI tank to turn left or right depends whether the center of the rock is more of the left side or the right side of the AI tank
        if (Physics.SphereCast(forward, 2.0f, out hitObject, 8.0f) || Physics.SphereCast(backward, 2.0f, out hitObject, 8.0f))
        {
            Vector3 difference = hitObject.transform.position - self.transform.position;
            TCA.rotation = Mathf.Abs(self.transform.forward.z) > Mathf.Abs(self.transform.forward.x) ?
                           -(difference.z) * (difference.x) : (difference.x) * (difference.z);
            return;
        }
        TCA.rotation = 0;
    }