Working with raycasts to deal damage

I drew up a small picture of how I want my raycasts setup but I haven’t messed with sending arrays from the center of an object or in this case a moving character. This is how I want my battle system to be instead of using trigger boxes which gets messy. Would be easier using raycasts instead. So each time my player attacks it deals damage to the enemies within this range infront of the player, which will also be set at a certain distance.

I’m not entirely sure what your question is; could you rephrase it?

This seems a very complicated way to do this, you should Use if(Vector3.Angle(yourTansform.position, enemyTransorm.position)<90) Rather than setting up lots of raycasts.

Well I wasn’t aware of that. Why does it need the players position and the enemies position? I want to be able to attack and deal damage to all enemies and players who enter that area infront of the player while attacking.

You can use raycasts for battle systems to deal damage if one hits an enemy or enemies. This would be used for a front attack system to check if an enemy is within that area using an angle.

Yes, I do understand that, but what is the problem you’re having?

  • Are you not getting how to use the ray casts?
  • Are the ray casts not functioning as you expect?
  • Are you wondering if this is a good idea?

I want to know how to call multiple raycasts infront of my character in order to use it for an attack system. I want my character to be able to attack at a certain angle infront of the character. Also as the character moves the raycasts should remain infront of the character. So pretty much if any enemy is within that front raycast area with a certain tag and the player uses an attack it will deal damage once in that area to all the enemies.

How the heck should it else know what to calculate the angle of? :wink: you wouldn’t want to have it start guessing :stuck_out_tongue:

I would call

Then check all the results if they are within the forward angle with somethin like

I think you can cast as many rays as you want, so you could put it in a loop starting from the left turning to the right. Which would look kinda like a cone infront of you. However I believe that this way is very expensive.

So this:

I think thats easier to set up and needs less computationpower.