Raycast Hitbox 4.01: For all your melee needs!

There really isn’t a “proper” way to use this module. It’s designed to be as easy as possible to fit any project of all sizes. This is general advice but if its readable, convenient, and doesn’t hamper debugging, then it should be fine. Ultimately, as you develop your game further, you will learn yourself what is best practice for how to implement it according to your needs.

I had a quick question. Is there support or features that show the vector 3 point or any offset position relative to the parts hit? The reason I ask this is because I’m trying to detect the position one of the raycast attachments comes into contact with an object so I can put a visual effect at that point. Or even if there’s a way I can get the specific attachment, I can find the point using the world position.

OnHit returns the raycastresult which in turn provides you with the intersection position.

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

This is amazing. The best way to solve hit detection. Thanks!

1 Like

I’ve got an issue with the module, the raycasts are not showing up correctly for me, here’s some code and a gif of what’s happening:

   local hitbox = Raycast.new(Character)
	

	hitbox.OnHit:Connect(function(hit, humanoid)
		if not hit:IsDescendantOf(Character) then
			print(hit.Name)
			humanoid:TakeDamage(Damage)
		end
	end)

	hitbox:HitStart(5)

https://gyazo.com/754aedc5e36f042938d2fa98df59448c

1 Like

Is this on the server? It looks like the server sees the weapon and animation at a different location than the client. See if the server is looking at a different position.

1 Like

The only thing on the client is a Remote Event doing :FireServer() inside of the ‘Punch’ tool script, the animation and the module are being used on the server.

1 Like

Since the server is handling this, you should check if the above is the case. Clients will see the animations play accordingly but the server may not have the proper animations replicated. The gif, from what I see, the animation plays on the server but the character does not have the “idle” animation which causes the rays to flatline at the end of the animation.

You should be able to see this by switching to the server view while testing in studio.

2 Likes

On the client, the tool is being held, however, the server doesn’t see the Punch tool being held, so on the server, the rays are accurate, but not on the client.

What should I do exactly?

Edit: Should I make an animation for holding the tool?

1 Like

Unfortunately, I don’t really have a lot of experience working with tools so it’s hard to come up with a definite solution. Honestly, I think it’s a Roblox bug that the default tool holding animation isn’t coming up on the server.


However, I can give some general insights on some techniques that may help. An idle animation may help since it doesn’t rely on the buggy tool to hold it for you. I would also make the client play the attack/idle animation. Load these animations on the humanoid’s animator, and it should replicate properly to the server with no issues.

Forcefully playing animations on the server, from what I’ve tested, always resulted in weird issues like you experienced.

2 Likes

Wow, thank you so much! I was looking for something like this for my game and this is so much more convenient than having to make it myself.

2 Likes

I have a sitation where a sphere shaped hitbox need to get bigger over time while it travels. Since the attachments will not also move as I tween the sphere, does anyone have any thoughts how this can be done?

It seems in cases like that that .GetTouching might be best, but i was hoping to stick with the raycasting.

1 Like

Can’t you pre-check the positions of the FINAL attachment positions when the ball is at its max size, And then tween the position of the attachments to the final position with the same time as the ball?

(Not WorldPosition)

EDIT: Actually… This won’t work, Since the attachments will spread more the bigger the ball gets, You could make a ton of attachments so they will all cover enough in the end, But that’ll be a lot of tweening to do…

1 Like

yeah this is the primary limitation of this GREAT module.

1 Like

I don’t think that’s something the module can fix while being performant

1 Like

This is a pretty cool module

It struggles with fast-paced fist fighting though, which is a shame.

https://gyazo.com/ade8fa94b3fb99e3720007bc1ddca5d5

Animations and the fist raycasting is done clientside and it still just doesn’t keep up when the anim speed is cranked.

Definitely keep it in mind if I’m working with longer melee weapons in the future though.

1 Like

It relies on CollectionService to determine if the hitbox should be deleted. It is using CollectionService:GetInstanceRemovedSignal to auto-delete hitboxes in case they are destroyed by external sources. If you want to remove this functionality, just comment out *line 223 in HitboxCaster

tagConnection = CollectionService:GetInstanceRemovedSignal(self.Tag):Connect(onTagRemoved)

Just be aware that you will need to meticulously keep track of all hitboxes, even upon deletion (this includes respawning of the characters, models, etc) as it can introduce memory leaks since these hitboxes can become unused overtime if you don’t destroy them properly.

Roblox is releasing a new method called Instance.Destroying which will supersede this method and shouldn’t auto destroy the hitbox, even parenting it to nil.

2 Likes

The module works great! But im not sure about security though, what i mean about that is i tried to do this on a server script on server script service and it didn’t work. You have to put it on the tool itself? So, can the exploiters access or manipulate the scripts since its replicated to them, or is there anyway that i can make the script on server script service? Overall this is a great module. Great work!!

1 Like

It does not matter where you put this on. Security is up to the developer to make proper sanity checks. This module does not help you with security. That is the developer responsibility.

2 Likes

But when its in servers script service it does not work? Ill try to debug tho…

1 Like