Melee combat

Hi guys :slight_smile:

I’m messing around with Unity and I got some questions.

If I was going to make a game with sword/bow and arrow combat, what would be the best way to take damage from enemies ?

I’ve been reading about raycast, but I’m not sure.

What do you guys think would be the best ? and I’m new to Unity :slight_smile:

Thanks for any reply!

Well, its not really that difficult it just takes time. You should set the sword to be triggerred and whenever the enemy hits the player, the enemie can send message to your players script where you can lower your health etc.

If your arrows are going to hit instantaneous, than a ray cast would be the way to go. I would think that you’d want a more realistic approach, so I would do as Rutenis said with the arrows as well: Give them an “OnTrigger” event to take damage from the player.

Triggers work well - depending on how fast your arrows move, you may want to consider a raycast approach, as small, fast moving colliders aren’t perfectly reliable.

Try a raycast & a trigger collider on the arrow. also make sure the arrow’s rigidbody has continuous dynamic collision set, to avoid the “passing through the player/enemy” problem I got when making a stomp attack for my character in one of my projects. (Yep, my character was stomping through the floor lol! :smile:)

Also have an ontriggerenter event in your script to detect the arrows. also tag your arrows “arrow” or something then add a tag check in the code so that the trigger knows what to pick up.

An arrow shouldnt be moving that fast… Ive never had any problems with projectiles going through colliders unless youre doing something stupid with the physics system.

A collision based system should work without any problem.

@JamesLeeNZ : Hi! No matter the speed, continuous collision detection will catch the arrow before it passes through the mesh. In fact, I think it works by tracing between the previous position with the new one, to make sure it doesn’t pass through the mesh!

And yes, a collision based system should work without any problem, aside some odd bugs with triggers sometimes. In my fighting game, for example, it is possible to touch once and have it register twice, which makes the damage amount dynamic, despite it being static. this bug could be a potential workaround for those games that are meant to have dynamic damage ratio generation… :wink:

I’ve only heard stories of bullets having that issue - people using tiny colliders with extremely high velocities. But it is quite possible that they were not using continuous collision detection!

I dont need an education on phsyics or the settings tbh… have a look at the game in my sig and youll understand why perhaps.

Not one of my projectiles requires continuous detection, and I have some reasonably fast projectiles.

@JamesLeeNZ : Really? You are one lucky man! :slight_smile: I had probs with stomping through floors, and that was with a character model!

Also wonder where the starter of this thread has gone? this is getting very off-topic… :eyes:

ATTENTION MODERATORS: If this thread looks liek it’s getting off-topic, and the starter of this thread doesn’t return, please close this thread!

1 Like

Not really… I just read the docs and made sure I wasnt doing anything wrong (eventually)