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!
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)
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.
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.
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.
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?
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.
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.
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.
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…
yeah this is the primary limitation of this GREAT module.
I don’t think that’s something the module can fix while being performant
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.
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.
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!!
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.
But when its in servers script service it does not work? Ill try to debug tho…