void Awake() { instance = this; deathScreen.gameObject.SetActive(false); List <Transform> walls = generateMapBounds(); HumanTankController = Instantiate(humanTankContPrefab, tankRoot, false); HumanTankController.Init( new Vector3(300, -800, 0), 0, PlayerManager.Instance.TankSchematic); Dictionary <string, object> data = DataPasser.Instance.RetrieveData(); TankSchematic enemyTankSchem = ((EnemyInfo)data["Opponent"]).TankSchem; AITankController = Instantiate(aiTankContPrefab, tankRoot, false); AITankController.Init( new Vector3(300, 800, 0), 180f, enemyTankSchem, HumanTankController.SelfTank, walls); MainCamera.GetComponent <ObjectFollower>().SetObjToFollow(HumanTankController.SelfTank.gameObject); DisableMovement = false; }
private List<Vector> GetPathToTarget(AITankController controller) { Map map = GameProcess.Current_Game.gameMap; Vector tCorner = map.GetSectorLocation(controller.Target.AbsoluteCenter); Vector pCorner = map.GetSectorLocation(GameProcess.Current_Game.Player.AbsoluteCenter); Point start = new Point((int)tCorner.X, (int)tCorner.Y); Point goal = new Point((int)pCorner.X, (int)pCorner.Y); List<Point> path = AStarSearch.FindPath(map, start, goal); if (path == null) { return null; } else { List<Vector> vPath = new List<Vector>(); for (int i = 1; i < path.Count; i++) { Vector v = new Vector(map.TileSize * (path[i].X + 0.5), map.TileSize * (path[i].Y + 0.5)); vPath.Add(v); } return vPath; } }
protected bool IsAttackState(AITankController controller) { Vector distance = GameProcess.Current_Game.Player.AbsoluteCenter - controller.Target.Gun.AbsoluteCenter; if (distance.LengthSquared <= Math.Pow(controller.Target.Gun.MaxFireRange, 2)) { return true; } return false; }
public override void Update(AITankController controller, Int32 dt) { if (IsAttackState(controller)) { Attack(controller, dt); } else { controller.CurrentState = new SearchState(); } }
public override void Update(AITankController controller, Int32 dt) { if (!IsAttackState(controller)) { List<Vector> path = GetPathToTarget(controller); if (path != null) MoveObject(controller, path, dt); else return; } else { controller.CurrentState = new AttackState(); } }
private void Attack(AITankController controller, Int32 dt) { //Look at situation when direction not updates controller.UpdateTargetDirection(new Vector(0, 0), dt); Vector direction = GameProcess.Current_Game.Player.AbsoluteCenter - controller.Target.Gun.AbsoluteCenter; direction.Normalize(); controller.UpdateGunDirection(direction, dt); if (Math.Abs(controller.Target.Gun.AbsoluteAngle - Controller.DirectionToAngle(direction)) < 5) controller.Target.Fire(); }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.tag != "Player") { if (impactEffect) { Instantiate(impactEffect, transform.position, transform.rotation); } UnityEngine.Object.Destroy(gameObject); } if (col.gameObject.tag == "Enemy") { AITankController ai = col.gameObject.GetComponent <AITankController>(); ai.currentHitPoints = ai.currentHitPoints - damage; } }
private void MoveObject(AITankController controller, List<Vector> path, Int32 dt) { Vector direction = GameProcess.Current_Game.Player.AbsoluteCenter - controller.Target.Gun.AbsoluteCenter; direction.Normalize(); controller.UpdateGunDirection(direction, dt); Vector moveCommand = new Vector(0, 0); foreach (Vector pathNode in path) { Vector nearDistance = pathNode - controller.Target.AbsoluteCenter; if (nearDistance.LengthSquared > controller.Target.Engine.translateSpeed.LengthSquared) { int delta_angle = (int)(controller.Target.AbsoluteAngle - Controller.DirectionToAngle(nearDistance)); if (Math.Abs(delta_angle) > 5) { moveCommand.X = Controller.CalculateRotateSign(delta_angle); } else { moveCommand.Y = 1; } controller.UpdateTargetDirection(moveCommand, dt); return; } else { continue; } } }
public GoInDirAction(Vector2 _requestDir, AITankController controller) : base(controller) { requestDir = _requestDir; }
public RotateAction(Vector2 _alignAngle, Vector2 _requestDir, AITankController _controller) : base(_controller) { requestDir = _requestDir; alignAngle = _alignAngle; }
private void OnTriggerEnter(Collider other) { Collider[] colliders = Physics.OverlapSphere(transform.position, explosionRadius, tankMask); // Go through all the colliders... for (int i = 0; i < colliders.Length; i++) { // ... and find their rigidbody. Rigidbody targetRigidbody = colliders[i].GetComponent <Rigidbody>(); // If they don't have a rigidbody, go on to the next collider. if (!targetRigidbody) { continue; } // Add an explosion force. targetRigidbody.AddExplosionForce(explosionForce, transform.position, explosionRadius); // Find the TankHealth script associated with the rigidbody. if (targetRigidbody.GetComponent <TankController>()) { TankController targetHealth = targetRigidbody.GetComponent <TankController>(); // Calculate the amount of damage the target should take based on it's distance from the shell. float damage = CalculateDamage(targetRigidbody.position); // Deal this damage to the tank. targetHealth.HandleTakeDamage(damage); } else if (targetRigidbody.GetComponent <AITankController>()) { AITankController targetAI = targetRigidbody.GetComponent <AITankController>(); // Calculate the amount of damage the target should take based on it's distance from the shell. float damage = CalculateDamage(targetRigidbody.position); // Deal this damage to the tank. targetAI.HandleTakeDamage(damage); } else { // If there is no TankHealth script attached to the gameobject, go on to the next collider. continue; } } if (explosionParticles) { // Unparent the particles from the shell. explosionParticles.transform.parent = null; // Play the particle system. explosionParticles.Play(); } if (explosionAudio) { // Play the explosion sound effect. explosionAudio.Play(); } if (explosionParticles) { // Once the particles have finished, destroy the gameobject they are on. ParticleSystem.MainModule mainModule = explosionParticles.main; Destroy(explosionParticles.gameObject, mainModule.duration); } // Destroy the shell. Destroy(gameObject); }
public ManeuverGoal(AITankController _tankController) : base(_tankController) { }
public AttackGoal(AITankController controller) : base(controller) { }
public AIAction(AITankController _controller) { controller = _controller; }
public Goal(AITankController _tankController) { Insistence = 0; controller = _tankController; }
public virtual void Update(AITankController controller, Int32 dt) { }
public JetInDirAction(Vector2 _dir, AITankController _controller) : base(_controller) { dir = _dir; }
public DodgeGoal(AITankController _tankController) : base(_tankController) { }
public FireWeaponAction(int _weaponIdx, AITankController _controller) : base(_controller) { weaponIdx = _weaponIdx; }