Raycast Hitbox 4.01: For all your melee needs!

Oh, sorry, it was an error with my script.
I had a bunch of AI with the same name “Guard”, and in the script that’s supposed to damage multiple guards, it adds their name to a table and checks if that name is already there.

1 Like

Sorry for bothering but how exactly do you make animations which work with this system?

I’m purely new to animation and I knew nothing, I’ve read this topic and did everything.

However, the rays don’t move at all and only move when the actual player moves. Take a closer look here: https://gyazo.com/221a3f3bb61ee8e7d0d8f0c897c023de

Is it an animation problem or is it my code problem? I’m pretty sure my code is fine, my best guess was that the attachments’ positions didn’t move together with the part. But I’m unsure, thanks!

I used Moon Animator to animate, SetPoints instead of making attachments for the hitbox

Animations should work right out of the gate with this module. There are pretty much only two things that can cause this:

  1. Your code. I don’t see any code so it’s hard to say much about it but you should be using SetPoints on the actual weapon and not torso for example (so the weapon influences the rotation of the raycasts).

  2. Replication issue. If this module is on the serverside, Server sees the position of your weapon differently from what the client sees. A good way to test if its your code or simply replication issue is to use attachments instead of SetPoints just to see if the issue still persists. If it does, it a roblox replication issue and the only solution at this time is to put the hit detection logic on the client side. If it works, it will be your code that is the root problem.


Again, im just speculating since I haven’t seen your script.

I tested it out and turns out it’s the replication issue. Do I just implement my system on the client side now?

I also used a loop to check the position of my sword. Turns out it actually changes its position on the client, but on the server nothing changes at all. What should I do? Could it be a problem from the new animator? (I used this module a while ago with LoadAnimation and it worked just as fine)

Visualization: https://gyazo.com/9b1bbfb017ea142db66ddda0bdba40c1

Edit: Visualization

Question, does this work with projectiles? Like grenades or bow arrows. Just checking because I tried this on the server and it isn’t the best hitbox on the server, should I switch to the client and replicate it, or am I doing something wrong with the hitbox attachments.

Unfortunately I’m actually not sure what causes the replication bug (I only seen it but never experienced it. Its a question that engineers or other people can give), only that putting the module client sided and then sending the target it hit to the server (with sanity checks) is the workaround. Unless there are some ways to fix the replication bug, putting it on the client is the only suggestion I can give at this time.


@rutheniumm This module can be used for projectiles however was not intended for that use. While it can be easily setup for projectiles, I would actually recommend FastCast for that since you will have more control over things like gravity (and also uses raycasting as a solution). You are experiencing server sided latency which is not the best experience, so yeah you can go with client sided preferably for maximum responsiveness or try the FastCast module instead which is designed specifically for projectiles.

If you want to keep using this module, there are a few solutions.

  1. Again, putting it through the client side with serversided sanity checks. This ensures the user gets the best experience with a little bit more work on the security.

  2. Increase the width of the hitbox with more attachments on the server to compensate for latency.

Great module and all, but i have partmode enabled and it doest want to return any parts, it keeps returning the Model, am i doing something wrong? or am i having an actual problem with this module, i’d really like to know

Can you post the snippet of code that uses PartMode? Your code should be somewhat similar to this for PartMode to work.

local hitbox = RaycastModule:Initialize(weapon, ignoreList)
hitbox:PartMode(true)

hitbox.OnHit:Connect(function(hit, _, raycastResult)
     print(hit)
end)

hitbox:HitStart()

Do note that it does not return the same parts until you call HitStop on the hitbox.

it suddenly started working again, guess thats cool? anyways thanks for the help

so i am trying to use this system to make an advanced sword combat where it includes blocking deflecting,etc. so i just need a way to see whn it collides with another hitbox how do i do tht?

On the Github link in the OP, there is a section in advanced tutorials about PartMode which should allow you to do what you are describing. It listens to part hits (like Touched events does) and you can use this to determine what to do once it hits a certain part / hitbox.

1 Like

so i was trying to use SetPoint instead of attachment and it stopped detecting hits.

i set points each time they atked using-


local points = {}
	for i= tools[tool].Tool.Hitbox.Position.Y - tools[tool].Tool.Hitbox.Size.Y/2, tools[tool].Tool.Hitbox.Position.Y + tools[tool].Tool.Hitbox.Size.Y/2,0.5 do
		for x = tools[tool].Tool.Hitbox.Position.X-tools[tool].Tool.Hitbox.Size.X/2,tools[tool].Tool.Hitbox.Position.X + tools[tool].Tool.Hitbox.Size.X/2,0.5 do
			points[#points+1] = Vector3.new(x,i,tools[tool].Tool.Hitbox.Position.Z);
		end
	end
	tools[tool].hitbox:SetPoints(tools[tool].Tool.Hitbox,points)

and yes i do hitstart and hitstop it worked before

Hello, I got a another question. Would this be more performant than casting a rotated region3 with the players limb CFrame and size every frame until a animation stops playing?

Idk why the rays do not appear in the first attack move, but it does after that
https://gyazo.com/6aeeaa40a974ed0b92edb5ed88aeea3d
I also test linkattackment. it is much laggy than use the original ray. With the original rays, I need to use many rays to get it accurate as I have with linkattackment . I haven’t tested with many players yet

I think the problem is with HitStart(). If I let HitStart(animation.length) → the first hit sometimes not work, but if i let HitStart(0.6)–> the first hit always work .@TeamSwordphin. I have no idea why this happen

it does print animation.length =0 at first hit wtf while it still plays the animation. idk why this happens.
Edit: ok I found the solution. Put this to check animation.Length so that the first hit will always work. Im not sure if it canbe laggy tho. Can someone confirm
while true do
wait()
if animation.Length >0 then
break
end
end

update i put a print inside the raycast module to print points inside if condition so tht all is working
update 2: there was a problem in my loop (i made attachments for the vector3s,tested,copied the tool object while testing,pasted in studio and saw the attachments pressed f and they were quite far away from hitbox)

@crazygamer817 Additionally you can turn on Debug Mode to see where the rays are ending up. SetPoints indeed works like attachments where the position property is relative to the attached part. The only solution for this is to keep checking where the rays are ending up.

@Neotrinax Region3s, as far as I tested, is one of the more performance heavy methods to detect hitboxes. Raycasts are lightweight and Roblox already does numerous optimizations for them in the backend. So I’d say yes, it is a lot more performant.

@Punkalox1 Animation Length property always returns zero the first few seconds it loads from an animator. This is because presumably, it is still trying to calculate how long the animation is. I would advise loading the animation(s) immediately when the character spawns if this is the case.

2 Likes

Do you what way to load the animation(s) immediately when the character spawns?

I assume you are doing something in the form of loading the animation immediately when you want to play the animation, like so:

function onSwing()
     local animation = animator:LoadAnimation(swingAnimation)
     animation:Play()
     hitbox:HitStart(animation.Length)
end

This does not guarantee the length to be immediately available.

What I would recommend doing is waiting till the animator comes up the first time the character respawns (if you are using a tool, you would simply wait for the humanoid). This is how I would personally load animations beforehand:

local character = --- your character here
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

--- Preloads the animations at the start of the script using a table
local animationsTable = {
     Swing = animator:LoadAnimation(swingAnimationObj),
     Swing2 = animator:LoadAnimation(anotherSwingAnimationObj)
}

function onSwing(animation)
     local animation = animationsTable[animation]
     
     animation:Play()
     hitbox:HitStart(animation.Length)
end

function mouseClick()
     onSwing("Swing")
end

function useASkill()
     onSwing("Swing2")
end

This is quite the rudimentary script and I wouldn’t copy and paste it line for line, but it probably should be how you should do your animations if the Length property is required. The more important takeaway here is to call LoadAnimation somewhere in the initial parts of your script, and not where you would want to use it immediately.