protected bool clean_LoS(bool Forward_Required = false) //Has direct Line of Sight to the player { int layerMask = (LayerMask.GetMask("Projectile") | LayerMask.GetMask("Default") | LayerMask.GetMask("InteractiveThing") | LayerMask.GetMask("Ignore Raycast")); layerMask = ~layerMask; //ignore these Vector3 target_dir = ETM.Return_Current_Target().position - transform.position; RaycastHit hit; if (Forward_Required) { float target_angle = Mathf.Atan2(target_dir.x, target_dir.z) * Mathf.Rad2Deg; float forward_angle = Mathf.Atan2(transform.forward.x, transform.forward.z) * Mathf.Rad2Deg; float diff_angle = Mathf.Abs(Mathf.DeltaAngle(target_angle, forward_angle)); if (diff_angle > 10) { return(false); } } Vector3 Modified_Start = new Vector3(transform.position.x, transform.position.y + RayCastheight, transform.position.z); Debug.DrawRay(Modified_Start, target_dir * 10f, Color.red); if (Physics.Raycast(Modified_Start, target_dir, out hit, MaxEnemyRange, layerMask)) { if (hit.collider.tag == "Player") { if (FL.ReturnIsEnemyCustomPlayer(ETM.Return_FactionEnum(), ETM.Return_customReputation())) { return(true); } } else if (hit.collider.tag == "BasicEnemy") { if (FL.ReturnIsEnemy(ETM.Return_FactionEnum(), hit.collider.gameObject.GetComponentInParent <EnemyTemplateMaster>().Return_FactionEnum())) { return(true); } } else { //Debug.Log((hit.collider.name, hit.collider.tag, hit.collider.gameObject.layer)); } } return(false); }
private void OnTriggerEnter(Collider other) { if (other.tag == "Player") { if (FL.ReturnIsEnemyCustomPlayer(ETM.Return_FactionEnum(), ETM.Return_customReputation())) { TargetsInMeleeRange.Add(other.transform); } } else if (other.tag == "BasicEnemy") { if (FL.ReturnIsEnemy(ETM.Return_FactionEnum(), other.gameObject.GetComponentInParent <EnemyTemplateMaster>().Return_FactionEnum())) { TargetsInMeleeRange.Add(other.transform); } } }
private void FixedUpdate() { enemies_nearby = false; int potential_enemies_in_range = TriggerList.Count; //Includes recently dead enemies for (int i = potential_enemies_in_range - 1; i >= 0; i--) { Collider col = TriggerList[i]; if (!col || col.tag != "BasicEnemy") { TriggerList.Remove(col); } else { EnemyTemplateMaster ETM = col.GetComponentInParent <EnemyTemplateMaster>(); if (FL.ReturnIsEnemyCustomPlayer(ETM.Return_FactionEnum(), ETM.Return_customReputation())) { enemies_nearby = true; } } } }