Forms Of Melee Attacking

Hi, I’ve been working on a dungeon crawler game. I’ve setup my player’s attack with a trigger so that with OnTriggerStay, and the attack button is pressed, it damages the collider’s game object inside. But ever since using this method, there have been errors, like it only works if the enemies move into the trigger, and not if the player just rotates to them. It also sometimes only attacks one at a time. By the way, I’m using character controllers, this seems to matter somewhat.

So I looked up some tutorials on how to make a dungeon crawler game. The best way I saw was to check all the object’s distances from the player and test to see if they were close enough. It also finds the dot product and checks to see if the object is in front of the player. But, with this method, if I was fighting a really big enemy, the enemy’s center would be too far away from the player to hit.

How can I make a decent melee attack? How would you do it? Here’s a video of another Unity game that has the style of a attack that I am trying to achieve: http://www.youtube.com/watch?v=aWR_wQ-PJq4

Thanks for your insight on this. :slight_smile: Any new ideas would be appreciated.

I honeslty have no idea mostly because i have not tried to implement an actualy combat scenario yet. However, i was reading your post, and thought, what if you used a secondary collider that was slightly larger than the body of the enemy. It would need to be as big as you would allow the character to attack it from. In other words, once player enters this outer trigger for the monster , he can successfully attack it. Basicly , very similiar to what yer doing, but using a second trigger to determine if yer in attack range or not.

Second trigger : isAttackable boolean , attached to monster script somewhere.

Just throwing ideas out there, not tried , not implemented , just wingin it. Hehe

Not sure if this will help, but the way I do it is that each weapon has a collider added to it, so a sword has a box collider that is just larger than the blade in all directions.

If you have a spear and only want the point to cause damage, just enclose the point in the collider.

This then is checked to see if it collides with the collider of the creature / object/ whatever you want to hit.

Assuming your creature colliders etc are proportional, then the differing sizes should not matter.

Regards

Graham

Calculating the distance to all enemies in the scene just to find which ones are in attack range would be an obnoxious waste of cpu cycles :slight_smile: I actually do it similarly, but instead of calculating all the distances, just use physics.overlapsphere with your attack range (this will solve your other problem, too, because overlapsphere will tell you if any point of the enemy’s bounding volume is within range, not just his center), then check the dot product to see if they’re within the frontal cone/angle.

willc, I’m not sure this method is going to be that kind to the CPU processing, because I’ll be checking
to see if my character’s inside the collider, for every enemy. And I will have hundreds of enemies per scene :/.

Moria:
Yah, I thought of that, but well, I kind of don’t have the sword model yet :smile:. It is probably the best method so far but, as I do not have a sword I can’t test it, yet.

Legend411, I will try this, it seems like a great idea. I see no reason why it wouldn’t work. :slight_smile: