About Shapecast

Do shapecasts work like this? Is it just like a very thin ray and at the end of it, it is just a detecting block/sphere with volume?


3 Likes

Shapecasts pushes the entire block or circle along the path

4 Likes

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:

3 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).