Hey guys, I’m currently working on trying to implement some abilities for characters, the ability I’m working on at the moment is meant to teleport the player forward and deal damage to all the enemies lying between where the player started and where they finished, with a certain with, so I’m using a CapsuleCastAll with a layer mask specifically for enemies and then merely calling a deal damage function for all the enemies returned, only for some reason it doesn’t seem to be hitting enemies that are CLEARLY well within the cast, and sometimes it returns none at all. I tried making the radius huge and it changes nothing.
p1 = myTransform.position + controller.center + Vector3.up * -controller.height * 0.5F;
p2 = p1 + Vector3.up * controller.height;
layerMask = 1 << 12;
abilityTars = Physics.CapsuleCastAll(p1, p2, controller.radius * 5f, myTransform.TransformDirection(Vector3.forward), range);
p3 = p2 + myTransform.TransformDirection(Vector3.forward) * range;
Debug.Log("enemies hit = " + abilityTars.Length);
if (range < 1.5)
{
Debug.Log("dashing into wall");
movement = myTransform.TransformDirection(Vector3.forward) * (range - 0.3f);
}
else
{
movement = myTransform.TransformDirection(Vector3.forward) * range;
}
controller.transform.position += movement;
int enemiesHit = 0;
foreach (RaycastHit hit in abilityTars)
{
if (hit.collider.gameObject.tag == "Enemy")
{
enemiesHit++;
GameObject Enemy = hit.transform.gameObject;
EnemyDamage enemy = Enemy.GetComponent<EnemyDamage>();
if (enemy == null)
continue;
enemy.SendMessage("ApplyDamage", 2);
stats.WriteText(Enemy.transform.position, 2, null, Color.white);
}
}
any ideas on what may be happening?