Is it possible to do a loop check of the hit function? I’ve tried numerous ways and I can’t seem to figure it out
Can you elaborate further? If you need a loop you can use OnUpdate, which runs on PostSimulation and check if the hitbox has hit something (or at least, hit something last):
hitbox:OnUpdate(function()
if hitbox.RaycastResult then
-- Does something repeatedly as long as the raycastresult is active. Or put it to nil if you want it to happen once.
end
end)
hitbox.RaycastResult returns the RaycastResult of the last hit item. OnHit is just a callback that activates when this property updates, but it will always be there in case you need to get the result somewhere else, or in this case, within the loop.
Does anyone have an example of creating a DmgPoint
attachment via the API? When I use a DmgPoint
attachment in debug mode, I can see the “red trails” clearly, but they don’t appear without it. Have I misunderstood the purpose of the ShapecastHitbox API, or is it possible to achieve this same visual behavior through code?
I can share my code even though it’s in TypeScript, the syntax should be pretty much the same.
With DmgPoint
attachment:
Via API:
const part = Workspace.WaitForChild("Part") as BasePart;
const hitbox = new ShapecastHitbox(part); // Equivalent of ShapecastHitbox.new
hitbox.SetCastData({
Radius: 0.1,
Size: new Vector3(5, 5, 5),
CastType: "Blockcast",
CFrame: new CFrame(0, 0, 0),
});
hitbox.HitStart().OnHit((raycastResult, segmentHit) => {
print(raycastResult, segmentHit);
hitbox.HitStop();
});
Am I missing something in the code?
Or am I doing everything with the API straight up wrong?
Hi, ShapecastHitbox doesn’t automatically create the points for you, nor does it give API to create it. You can do the following (convert to typescript as needed):
local hitbox = ShapecastHitbox.new(part)
local dmgPoint: Attachment = Instance.new("Attachment")
dmgPoint:AddTag("DmgPoint")
dmgPoint.Parent = part
hitbox:Reconcile() -- If the attachment is created AFTER the hitbox has already been created, Reconcile must be called
hitbox:HitStart() --- do you things
In conclusion, you should make your own API that interfaces with ShapecastHitbox to create the points for you.
Oh, I see! Thanks! So does the API change the attributes on the attachment? And if so, what happens if you have multiple attachments? What does :SetCastData()
actually do?
Edit: Nevermind looked at the code. Thanks very much! Very cool module👍
Is this expected behavior? Shouldn’t the hitbox have hit way sooner?
Never mind again, might have been a one-off. Works like a charm, sorry for the series of messages. Thanks for the support, you and your module are awesome!
Hi all, with the introduction of the following:
This is pretty huge for the raycast libraries as now anything can be detected as a hitbox. No code changes are needed, just that when you reconcile, take care that attachments inside folders, etc, can be seen as a valid hitbox point now.
v0.2.5
ShapecastHitbox now supports Bones and Mesh Deformation, similar to its predecessor, RaycastHitbox. Does not require any external constraints, just add DmgPoint tag to the bone and it should be a valid damage point.
any progress on trying to get stationary hitboxes functional? this is a really big drawback of this module
Hi, I replied to an earlier post about this. If you could test this, thank you.
The key is to make multiple shapecasts that makes up the hitbox, rather than one large one.
Is this a limitation with the original raycast hitbox as well?
Indeed it is. Mostly because Raycasts aren’t designed to be stationary. They are lines within a set distance. By making them do something else then what they are designed to do, technically they wouldn’t be raycasts anymore.
Nonetheless, I posted the above reply, I have yet to receive confirmation if its working. Fundamentally, there is only so much I will be able to do since its just how raycasts behave on a game engine level.
If you need much more accurate stationary hitboxes, I employ you to use spatial querying instead.
Is there a way to see which attachment/ray hit something? When I use shape cast I can see in debug mode that it illuminates whichever shapecast it is green, but I can’t figure out how to get the associated attachment with it.
Yes, Onhit returns the segment hit.
hitbox:OnHit(function(raycastResult, segment)
print(segment.Instance) --> Attachment
end)
Does this use generalized shapecasts?
Side note how can i view the shape shapecasts makes? It’s kinda hard to visualize the hitbox it creates with just script.
Last question:
Do u think its ok to code the hitbox on server script if the game only has 4 players per server(excluding spectators)?
Hi there, for now it is only limited to primitive shapecast shapes. Generalized shapecasts are on the roadmap.
To view the shapecast shapes, ensure the debug lines in the settings is enabled. You can also do this via a script. The playground place has an example on how to do this.
Depends on your game. Serversided hitboxes are fine if you don’t need insanely accurate hitboxes and can take a little bit of a delay fine. It’s up to you. My own hack and slash game is server sided hitboxes and it served fine. Could it be better? Yes. But for my use cases it’s not a significant problem.
Ok btw where can I get the latest version of this? I feel like the one on marketplace is outdated, tested it.
It’s not recgonizing the second DmgPoint… If I move the second DmgPoint to the first Hitbox, the second DmgPoint’s position changes from the second hitbox’s center (where I want it to be) to the first hitbox’s center, thus forcing me to have 2 hitbox reference instances so I know where to put the DmgPoints, the hitboxes will be turned off on the visibility scale when I’m actually playing, I just copy the number of each of the hitbox isntances size to the DmgPoint’s attribute “CastSize” so ur module will know
btw I’ve tested genearlized shapecasts, lowkey overrated other then donut shapes.