I want to replace touched with raycast for better hit detection. So for simplicity, how would I use raycast in a kill brick? Or when making a simple fireball, and just replacing touched with raycast?
Coming from someone who actively scripts abilities, I would suggest using magnitude over raycast for the bulk of your abilities. Raycast should be used with more intricate work or like abilities with specific conditions. Magnitude works perfectly fine and you have plenty of control with the range thats detected.
The way ill usually do it is, after I launch my skill or whatever ill set up a loop for my magnitude, and ill have a condition to prevent it from looping after the skill is gone > youll have to do this if its raycast or magnitude.
local plr = game.Players.LocalPLayer
local char = plr.Character
local active = true
local foundtarget = false
while active == true and foundtarget == false do wait()
local mag = (part.position - humrootpart.position).Magnitude
if mag <=2 and humrootpart ~= char.HumanoidRootPart then
--send damage request to server
end
end
Another reason I suggest using magnitude is because its simplistic to use, raycast can get super annoying to deal with and its not exactly user friendly to learn. For your first skills magnitude should be easy enough for you to experiment with since almost everything with magnitude gets set up the same way.
Now above I showed what an example of what magnitude in an ability could look like > there are problems with that script, like for instance I obviously didnt account for players or anything like that, its just a rough example. Now I’ll show you what a rough example of a kill brick could look like.
local go = game.Workspace
local plrs = game.Players
while wait() do
for i,v in pairs(go:GetChildren()) do
for e,g in pairs(plrs:GetChildren()) do
if g.Name == v.Name then
if v.Humanoid ~= nil or v.Humanoid.Health ~= 0 then
local mag = (script.Parent.Position - v.HumanoidRootPart.Position).Magnitude
if mag <=5 then
v.Humanoid:TakeDamage(100)
end
end
end
end
end
end
^ as you can see in the example above its not too much different from using touched > the only difference is you’re actually having to identify and locate players > using magnitude makes this decently easy for you. ^that kill brick script should work even though im writting it off the top of my head the logic should be fine > that first example for the skill wont work, but it should give you a decent idea for how to go through the process of scripting it.
One more thing to note using raycast is somewhat the same > the setup is pretty similar, but raycast has a lot of things you can mess with which is what makes it more tedious to deal with in skills. Raycast should be used for more heavy duty work otherwise magnitude is pretty good for most of your cases > region3 is also acceptable, but I’m biased toward magnitude since its so easy to use lol.
Hopefully this helps
Interesting, I was trying to learn raycasting but it seems too complicated for a beginner like me. So I’m gonna try and stick with magnitude, thanks for the answer!
Thanks for this! I have been looking for a new solution as well.