Hey guys,
So I noticed that the way this is done in the course is by looking for IDamageables, which causes the Player to also receive damage as it also inherits from IDamageable.
The way I approached it is by making use of LayerMask in the SphereCastAll params.
public void Use(AbilityParams abilityParams)
{ int layerMask = 1 << 9; // 9 is enemy layer RaycastHit[] enemiesInAreaOfEffect; float damageToDeal = areaOfEffectConfig.GetDamagePerTarget(); //Is casting Ray here as well as in CameraRaycaster an issue? Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); enemiesInAreaOfEffect = Physics.SphereCastAll(ray, areaOfEffectConfig.GetRadius(), areaOfEffectConfig.GetRadius(), layerMask); foreach (RaycastHit enemyHit in enemiesInAreaOfEffect) { var damageable = enemyHit.collider.gameObject.GetComponent<IDamageable>(); if (damageable!= null ) { print(damageable); print("layermask " + layerMask); damageable.TakeDamage(damageToDeal); } }
Any thoughts on this would be appreciated