I want to make a melee system using raycast but i have 0 idea how it works, can someone please explain how you can use a raycast to make a melee system if you know how? thanks!
Raycasting isn’t that effective of a method to make melee weapons, but I’d assume (since I’m unsure what your case is) that a short raycast to the mouse click position would suffice if there are no mechanics other than damage?
I guess that can work as a limiter of range but seems only good for first person melee systems, i want a third person melee system. And with what you said about it not being a effective method, what’s the most effective method in your opinion?
you could make a collision based melee system. when the tool is activated, run the animation and then if someone collides to the weapon’s hitbox then they get damaged. if you’re going to do this, only let the touch event run when the player is going to attack or anyone who touches it will get damaged even when the tool is not activated.
Try looking into this module by @TeamSwordphin:
This module is super easy to use for beginners, and offers a bunch of customizability for advanced users, such as hitbox groups.
One thing to note here that it doesn’t mention on the main post is that you should use the module on the client side, then fire a remote event when you hit a player, and do checks on the server. The hit detection is really good, but only on the client. The hit detection is unreliable on the server, it sometimes works, but I highly encourage you to use it on the client.
Since raycasts can detect if there is a part in a direction, it can be very useful for melee hit detection.
The green circles are the attachments along the sword, shown by the black lines. When the attack with the weapon begins, raycasts (the red arrows) are fired, from the attachments, every frame (raycasts are extremely performant) along the sword, so we can detect is the sword will come into contact with something. Since performing a raycast returns a result, we check the result’s instance if we hit a character. When the attack stops, the raycasting stops.