Hello!
I need some advice on whether or not doing a distance check between a bullet and an enemy is better performance wise than OnCollisionEnter().
Right now I have my bullets only collide with enemy and wall/platformer layers and they are “destroyed” (or deactivated since I’m pooling) with OnCollisionEnter. Same goes with the enemies receiving the damage code - tied to OnCollisionEnter();
These bullets don’t move at super realistic speeds- it’s a stylized side scroller so think of contra or megaman speed of bullets.
Alright so would
Update(){
if(distanceFromEnemy < 0.5){
//destroy and damage
}
}
or
OnCollisionEnter(collision : Collision){
//layer check
//destroy and damage
}
be more efficient?
I would like to keep the distFromEnemy in an Update() to make sure there’s enough accuracy of the detection. Also if it IS distFromEnemy how would I go about defining distFromEnemy if I have a bunch of enemies on screen? Some sort of array I suppose but how should I check?