Introducing Shapecasts

This is really useful! Thank you Roblox. Raycast is good but I love bigger shaped hitboxes so it’s easier for the player to hit someone, very happy it gives the .Position argument which OverlapParams doesn’t. Can’t wait for the maragin bug to be fixed, I will probably switch to this as my preferred hitbox system.

4 Likes

This is amazing! I might find it useful for a lot of my projects. Thanks Physics Team!

4 Likes

Love this and can’t wait to use it!

Just one thing, in the Code Samples of the Blockcast & Spherecast documentation there seems to be an error where Direction was used instead of Distance. Not sure if it will be changed to Direction but I just thought I’d point it out.

print("Distance until hit was found:", result.Direction) -- should be result.Distance
4 Likes

Out of curiosity, what use case would you have for pill cast?

4 Likes

Will this allow us to get the intersection point of a touch between two parts? I feel like with this, that would be somewhat possible. But what if an entire surface is in paralell with another? Where would the intersection be?

4 Likes

Partcasts are planned. :slightly_smiling_face:

21 Likes

Thanks, we’ll get this example fixed.

3 Likes

We’re thinking about batched shapecast or partcast APIs. They might work by passing an array of parts, so you could build your own model cast.
Do you have any use cases in mind?

13 Likes

thanks, but will it be like what I expected?

raycasting from the part without the CFrame nor Vector3 and only a few arguments

4 Likes

Finally.
This was REALLY needed! Good job.

4 Likes

@subcritical, Will there be any way of visualizing the raycasting like the videos shown?

10 Likes

Perhaps you could use model casting in a case like this:

The player has a special ability to throw a large boomerang, which can be dodged because of it’s hitbox. When the boomerang is thrown, it casts a Model Cast of itself from it’s current position to the new position and updates it’s position to the new position every Heartbeat.

Enemies may be able to dodge it by jumping over, or possibly stay in the middle of the boomerang if they have enough speed and timing to do so, and this is because the model of the boomerang’s design.

Using a model cast here would be efficient, since it’s using an accurate resemblance of the boomerang as it’s hitbox.

Not sure if this is already a thing, but if there is a way to also define the end orientation of the shape casts, the boomerang would be on board with using it.

3 Likes

I don’t think modelcast is a good idea, You can make a module for modelcasts like this (this is a proposed idea, it won’t work as partcasts aren’t implemented yet but is planned)

return function(model:Model, direction:Vector3, params:RaycastParams?)
   for _, v in model:GetChildren() do
      if v:IsA("BasePart") then
         workspace:PartCast(v, direction, params)
      end
   end
end
4 Likes

Also, something I realized, you could probably just use Unions as your way of using Model Casting, assuming that PartCast can be used on Unions.

3 Likes

it’s arguably taken way too long for this to be a thing,i am looking forward to performance improvements!

2 Likes

well, it’s out now, so there’s no need for such negativity

6 Likes

yes, but it won’t always work, sometimes when we union parts, it doesn’t work

1 Like

This is fantastic! Large projectile hitboxes are finally somewhat optimal!!!

2 Likes
local params = RaycastParams.new()

params.FilterDescendantsInstances = {workspace.Model}

local part = workspace.Part

local direction = part.CFrame.LookVector * 100

local result = workspace:Spherecast(part.Position, part.Size.X / 2, direction, params)

if result then

local finalPos = part.Position + direction.Unit * result.Distance

print("Object/terrain hit:", result.Instance:GetFullName())

print("Hit position:", result.Position)

print("Final position:", finalPos)

print("Surface normal at the point of intersection:", result.Normal)

print("Distance until hit was found:", result.Direction) --It errors here | It should be result.Distance

print("Material hit:", result.Material.Name)

else

print("Nothing was hit!")

end

image
Good evening, I think that I found an error in this script (it can be viewed in the image)!
It was posted on Documentation page: WorldRoot | Roblox Creator Documentation

2 Likes

What’s the minimum size for a part to be casted?

1 Like