About Shapecast

Well, How would I achieve a hit detection effect with spherecast on a projectile like this?



The path is only in one direction but how can I have it detect parts from all directions?

Edit: Or is :GetPartsinPart() Better for this?

2 Likes

I was hoping for SphereCast to be like SpatialQuery hitbox except better accuracy and performance.

What if you use GetPartBoundsInRadius()

I have tried hit detection using those methods before. It works perfectly fine but not exactly that well on fast-moving projectiles.

What if you kept retrieving the result.position multiple times? Do you think that could give all the points that touched the raycast?


Well what I want is simply to just have it be exactly at the center. I just have no idea how to set the direction argument for it

I’m sorry then, cause I don’t really know how to.

Typically, the method used is spherecasting between the projectile’s position on the last frame and its position on the current frame.

2 Likes

Such as

:Spherecast(Blast.Position, Blast.Size.X/2, LastPosition-Blast.Position, Params)
1 Like

Roblox doesn’t have build in sphere casting like unity. The best way IMO is to fake/approximate it with multiple raycasts. For example, with a sphere cast you could do multiple raycasts along the edges and in the center (depending on size, for larger ones you’ll need more in the middle). If you want it to be more accurate you could polish up the result with short raycasts at the end to find the exact first collision point for the sphere cast.

Edit:
Shape casting was released a few days ago as Twexdy pointed out.

Actually, Roblox very recently released an update to support shapecasts:

2 Likes

Yes, this should work fine. Just don’t forget to declare the LastPosition variable outside of the connection.

2 Likes

No way, that’s awesome! That’s been such a highly requested feature for so long now.

Thanks for letting me know!

2 Likes

I’ve tried this and it only detects parts that are in front of it, such as a wall or player. Doesn’t work on floors (baseplate), instead it just phases through them

And even then, the hit detection is really late as the projectile only stops moving a second AFTER it was phased through the wall

Can you provide more context on the code of your projectile?

This is because blockcast/spherecast/shapecast does not detect parts that initially intersect the shape as of right now (I believe this might change I could be wrong) for now u can stick to just raycasting or if u do require shape/volume for your projectile I recommend looking at alternative methods like .Touched which is not performance demanding or alternatively GetPartBoundsInRadius which is resource demanding.

I wouldn’t mind using .Touched, but what’s with all this concerns about it being ‘exploitable’? If I create the .Touched connections on server, and SetNetworkOwner to nil, what do i have to worry about?

.Touched events are unfortunately exploitable even if the part connected to the event is owned by the server because it seems like the event is client controlled(could be wrong about this); if you were to move a part on your client with .Touched connected the server has networkownership of(anchored) that part it will still trigger the event even if it only touched anything on your client. This is a problem with a fix that can be implemented with validation before rewarding an outcome when the event is fired.

However the bigger concern or fallback of .Touched event is the inaccuracy of collision detection due to it running in the physics engine which runs at a different framerate(60 - 240hz) than the script engine(60hz).

So from what I read,

If I make a part on the server and create a .Touched event on the server too, A client can move that part on their side to trigger the touched event? And to achieve this the part must be anchored? what if the part is unanchored will it still happen?

And to fix the above problem, to apply validation (do you have an example? because if I generate a .Touched fireball on the server, the validation that comes in mind is detecting if the fireball is actually close to the user)

Lastly, what does SetNetworkOwner do for this, does it patch any exploit or?

if the part is not anchored i believe the same happens? im not entirely sure you can test it out to see if setting network owner to another player and see if others can use that part to trigger anything.

For something like a fireball; you can check if at the hit registered time based on their logged last position and hit position if a hit was possible based on the projectiles velocity; remember to always include a leniency so as to not cause false positives when creating antihacks/antiexploits.

SetNetworkOwner basically means u hand over the physics of a part to a owner i.e they can do anything to manipulate its cframe, position, orientation, etc… this does not patch any exploitation but rather setting it to anything except the server invites exploitation; The reason you would set the networkowner to anything but the server is for smooth physics replication for clients for example your character model in game is owned by your client had it been on the server it would have been a very laggy experience for you.