Best practice combat

Hi guys, i would like to ask your oppinion about the best way to implemente two types of attacks in a top down isomectric click to move ARPG(already move and melee attack working, 1st the attack that damage all enemys in front of player inside a cone and other one inside a circle center in player, this will be more efficiente with collider/triggers or raycast/hardcode?

Appreciate any info/help.

It depends on the type of attack. Is it a shot or explosion that radiates outward and should only hit the targets in the front? Raycasts might work better for this in some cases. You could also use colliders and then use some position checking algortihm.

Is it variously shaped AOE attacks? You can just use triggers + OnTriggerEnter for that.

ok an example of both are a spin attack(player rotate like 2 seconds and damage all enemyes inside a certain circle), and the other like a floor hit that damage in cone all enemys… something simple in diablo lines :slight_smile: and sry its probably simple but im kinda new in script

You’ve got a bunch of choices. The most obvious ones are:

1: Use colliders that keep track of what’s inside them and not. When you click the “hit” button, do damage to all the things currently inside of it.
2: Use a collider that you turn on just as you do the attack, and do damage with OnTriggerEnter
3: Use some kind of overlap-shape. Physics.OverlapSphere and similar methods.
4: Do a bunch of raycasts in the direction you’re hitting.
5: Have a list of all of the enemies, check if they should be hit or not

We’re using 2 for our game, and it’s working pretty well. The great thing about using colliders is that you can see in the editor exactly what you’re going to hit or not. Colliders are also pretty damn fast.

The downside is that if you don’t already need colliders for your enemies (ie. you’re moving stuff with NavMeshAgents), you suddenly need to put them in there.

1 can be a great way to do things - especially if you need to know things like “will the player hit something if they click the button” before they actually attack. The problem there is that invisible colliders that’s hanging out in the scene has a tendency to get hit by raycasts you’re trying to hit other things with, so you have to be very careful with layers and layermasks.

The raycast solution is very good for projectile weapons. If you’re shooting a gun or a fast projectile of some sort, definitely use raycasts. If you have a sword that swings in an arc, raycasts make very little sense, though.

5 is just for very special situations. You can avoid all colliders and the iffyness of checking the physical world, but if you have a lot of enemies around, it will become slow very fast. You’ll also end up having to maintain a list of all the enemies, which will be a pain.

Yes, im using navmesh for player and enemys since im using click to move, and right now the enemy has a sphere collider so when the player enters thats it hit enemy until dead or i start run out. but i hv a little issue, after enemy die, the player always run the attack animation an extra time too… seems i hv to configure the animation to only give damage in a certain animation frame (dont know who yet xD)… so seems that a little thing is getting a bit complicated :stuck_out_tongue: thx for the info anyway