Why is raycasting or magnitude considered better than touched?

People always say that raycasting and magnitude are better than touched in scripting melee combat. But why is it better though? Isn’t touched more simple?

Its because using Touched is not that reliable in detecting touches sometimes. You can still use it though and I’m pretty certain the default roblox sword uses touched instead of rays.

Seems more like a matter of the pros and cons of each method. There is no real objective position on the matter but some things may work better than others. Most of these methods are bottlenecked primarily by inherent slowness checking hits on the server done by clients or hit legitimacy if hits are checked and sent by the client to be registered.

I would assume the main reason melee systems dislike using Touched is because of the need for physically simulated objects to intersect. I’ve used a Touched system for a PvP project back in 2018/2019 and I had countless complaints about hit detection being horrible. Part of this was because I did not handle already-intersecting parts correctly (nor did I know how at the time).

Personally I think Touched is still fairly viable and you’re free to use it so long as you can handle the various cases around it. I preference raycasting now though because you don’t actually need to rely on physics simulation or anything to get your hits done, meaning that even stationary objects that should deal melee damage can do so. After being opened to the world of raycasts for melee, never looked back. Unless I’m lazy and that’s a different story altogether.

1 Like

touched has a slight delay compared to raycast and magnitude > If you’re like doing kill bricks or simple touched things to activate doors or whatever that’s fine. However if you’re trying to make skills or bullets you’d want to use raycast or magnitude or even region3 due to how much more direct it can be exactly when it comes in contact with the player. For example about 4-5 months ago I made a beam clashing system > where 2 beams hit each other and the players would have to spam keys to win the clash > if using touched sometimes the clash wouldn’t activate or would activate for only one person, aside from that the skills would go completely past each other > but when using raycast it was instantly working how it was intended to. Touched does have a place for certain things, but generally I think raycast/magnitude will always be better

How would I use raycast to make abilities? I’m trying my hand at making abilities and all IK are how to make them with touch

Say you’re making a fireball > Keypress > animation plays > fireball shoots out in direction > set a loop and inside the loop have it raycast in front of the fireball and as it comes in contact with objects have it check the distance between and the object its come in contact with > with raycast its decently easy to find what objects you’re targeting. I usually prefer to use magnitude, but magnitude is checking around the entire skill itself rather than a general direction. > but after your raycast comes back positive for a player just target the humanoid and deal damage. I personally will do something like client to server then server to client to spam the raycast/magnitude loop then back to server if something came true. I also have a event for removing the skill > if within a 5 second period or however long I want the skill to be active > if that time passes ill send a event back to the client setting a bool value false or true, which would end the loop preventing everything from getting super laggy. Theres a lot of ways to go about it and theres no 1 correct way I think its whatever you personally enjoy doing. This is just how iv done it for the past 2-3 years now. But that should give you a basic idea of how to set it up at least.