How would you make a sword? (Raycasting, Touched, etc)

I’ve been trying to make a sword using .Touched, but it keeps detecting the player instead of the target. I disconnect the touched event right after so it isn’t damaging when the player isn’t swinging their sword. I’ve looked at other methods and I’ve seen people talk about Raycasting and Region3’s. However, these methods seem expensive on performance. Issue was fixed, but I still want to hear how some people make swords :smile:

How would you make a sword?

5 Likes

You can check if the part that the sword hit is part of the character with IsDescendantOf.

local IsPartOfCharacter = hit:IsDescendantOf(Character)

Depends on the size. A tiny region check/raycast won’t be very expensive, but raycasting thousand of studs or with a giant region could be very costly. Swords would generally only need small region checks or raycasts, so performance shouldn’t be a big deal. Region3s are all boxes, so if you wanted more accurate collision detection, you might want to use GetTouchingParts.

The last time I made a sword, I used a .Touched event. If you wanted a sword which would deal damage once per swing then you would probably want to use a raycast or check all parts touching the sword.

What you do to make a sword is up to you, and what you want to happen. The methods you listed have their own use cases, so it would be helpful if you elaborated on what kind of sword you were making.

3 Likes

Yeah I just figured out the issue with my sword about a minute ago, thanks!