Hello!
I was working on a weapon hitbox using raycasting, which is attached to… well, two attachments.
Since I am new to raycasting and I am such a little baby , it doesn’t work (real shocker there…)
Heres my script: (not full, just raycast)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {tool.Parent}
params.IgnoreWater = true
ray = workspace:Raycast(attach0.WorldPosition, attach1.WorldPosition, params)
RayCast() takes a Direction as its second argument, not an end position. You can read more about raycasting here.
Assuming you want a ray to go from attach0 to attach1, you might want to do this instead:
local origin = attach0.WorldPosition
local direction = attach1.WorldPosition - attach0.WorldPosition
ray = workspace:Raycast(origin, direction, params)
Im trying to make a weapon that does damage using raycasts cause .touched is unreliable.
The attachments are inside of a part of a weapon and scale from the bottom of the blade to the top
I am using attachments so I dont have to create a ton of parts
A .Touched event might be more suitable for a sword than rays. If you’re worried about the event being unreliable, you could add a debounce or lock variable to stop it from firing too many times in one swing.
I already looked at that. It does not suit me very well, and I would much rather script it myself because thats how I learn. I dont learn by just slapping models into my tool
Understandable, but here is what I did if you needed help; local origin = ((yourorigin)) local direction = (mouse.Hit.Position - origin).Unit * MaxRayDistance local rayParams = RaycastParams.new() rayParams.FilterDescendantsInstances = {workspace.Baseplate, player.Character} rayParams.FilterType = Enum.RaycastFilterType.Blacklist local result = workspace:Raycast(origin, direction, rayParams)
I appreciate your enthusiasm to learn and try things out for yourself, but it’s much easier to use existing code than reinvent the wheel. Besides, nothing stops you from examining the module’s code and learning it that way, even if you don’t want to use it.
Aside from that, if the module didn’t suit you, it’s unlikely that using raycasting techniques for hitboxes will either; I’d still recommend using a .Touched event. Did you enable the debounce variable correctly when you tried it last time?
Yes. When I used the touched event, I made it able to disconnect so it wouldnt do damage when the sword wasnt swinging. That didnt change anything, though. When the sword already swung, it did damage after the animation was done
Exactly. My friend made a touched event weapon and it fell into shambles. Touched events are also heavily unreliable for falling objects that do damage. If you just stand still, the touched event wont fire.
You could use instance to make the hitbox part and cframe and parent it to the area you want it and then destroy it using :Destroy() make sure you use debounce