- Home /
Question by
OmerPasa3328 · Nov 27, 2021 at 07:00 PM ·
colliderarrayscollider2drangeoverlap
Physics2D.OverlapCircleAll returning colliders outside of the area
Hello, I do have 2 objects with same code but one is working fine just attacking when player in range but other Even range is 0 it is detecting player collider and it has damn same code. it working fine all code is working but it shouldn't.
// so why even though range is 0 and collider given to code is wayyy far away this is working?
Collider2D[] enemiesInRange = Physics2D.OverlapCircleAll(attackPos.position, attackRange, whatIsEnemies);
if (timeBtwAttack <= 0) //making sure it isn't attaking always
{
if (enemiesInRange.Length >= 1) // my collider detector
{
Debug.Log(enemiesInRange.Length + "ENEMİES İN RANGE");
Debug.Log("Player_In_Range!!");
//for giving every one of enemies damage.
for (int i = 0; i < enemiesInRange.Length; i++)
{
isAttacking = true;
playerScript.GetComponent<PlayerScript>().PlayerTakeDamage(damage);// that code should not work .
Invoke("AttackComplete", damageDelay);
}
}
timeBtwAttack = startTimeBtwAttack;
} else
{
timeBtwAttack -= Time.deltaTime;
}
Comment
I think it might be problem public variable witch was changed in inspector.
Try changing the variable in inspector for nonworking player
nope :( changed to private but no luck it still sees colliders outside of area
Best Answer
Answer by OmerPasa3328 · Nov 28, 2021 at 11:09 AM
Ok ok I find out, layer has changed to player ' s layer so yeah it is in range all the time xd