protected virtual void moveTowardsTarget() { if (smart) { //GetFlakList(); ProjectileScript threat = findProjectileInRange(); FlakScript threat2 = findFlakInRange(); if (threat != null || threat2 != null) { smartAvoidance(threat, threat2); } else { transform.position = Vector2.MoveTowards(transform.position, targetedPosition, moveSpeed * Time.deltaTime * GetLevAndEngineAceel()); pointTowardsTarget(targetedPosition); } } else { if (targetLocked) { transform.position = Vector2.MoveTowards(transform.position, targetedShip.transform.position, moveSpeed * Time.deltaTime * GetLevAndEngineAceel()); pointTowardsTarget(targetedShip.transform.position); } else { transform.position = Vector2.MoveTowards(transform.position, targetedPosition, moveSpeed * Time.deltaTime * GetLevAndEngineAceel()); pointTowardsTarget(targetedPosition); } } }
void smartAvoidance(ProjectileScript threat, FlakScript threat2) { if (threat2 == null) { aroundMissile(threat); } else { if (threat != null) { if (Vector2.Distance(threat.transform.position, transform.position) < Vector2.Distance(threat2.transform.position, transform.position)) { aroundMissile(threat); } else { aroundFlak(threat2); } } else { aroundFlak(threat2); } } }
void aroundFlak(FlakScript threat2) { Vector2 aroundThreat = AroundDangerPoint(threat2); Vector2 avoidenceVector = targetedPosition * 0.3f + aroundThreat * 0.7f; transform.position = Vector2.MoveTowards(transform.position, avoidenceVector, moveSpeed * Time.deltaTime * GetLevAndEngineAceel() * 1.25f); pointTowardsTarget(avoidenceVector); if (!smartAvoider1.gameObject.activeSelf)// || Vector2.Distance(smartAvoider1.gameObject.transform.position, transform.position) > 2) { smartAvoider1 = null; } }
protected override void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Ark") { collideWithArk(); } if (other.gameObject.GetComponent <FlakScript>() != null) { FlakScript thisFlak = other.gameObject.GetComponent <FlakScript>(); if (Random.Range(0, 10) < thisFlak.Effecitveness()) { die(); thisFlak.Impacted(); } } }
Vector2 AroundDangerPoint(FlakScript threat) { float offset = 4.0f; if (smartAvoider1 == null) { smartAvoider1 = threat; if (Mathf.Abs(transform.position.y - threat.gameObject.transform.position.y) > Mathf.Abs(transform.position.x - threat.gameObject.transform.position.x)) { smartAvoiderChoice = 0; return(new Vector2(threat.GetTargetedPosition().x - offset, threat.GetTargetedPosition().y)); } else { if (Random.Range(0, 2) == 0) { smartAvoiderChoice = 2; return(new Vector2(threat.GetTargetedPosition().x, threat.GetTargetedPosition().y + offset)); } else { smartAvoiderChoice = 3; return(new Vector2(threat.GetTargetedPosition().x, threat.GetTargetedPosition().y - offset)); } } } else { if (smartAvoiderChoice == 0) { return(new Vector2(threat.GetTargetedPosition().x - offset, threat.GetTargetedPosition().y)); } else if (smartAvoiderChoice == 2) { return(new Vector2(threat.GetTargetedPosition().x, threat.GetTargetedPosition().y + offset)); } else { return(new Vector2(threat.GetTargetedPosition().x, threat.GetTargetedPosition().y - offset)); } } }