Taking off projectile size for raycasting

I’m trying to get a projectile to hit a wall and bounce, and it’s pretty much working, but one problem I’ve noticed is that the projectile clips through a bit because of how the raycasting works.
I tried subtracting the part size from the end destination, but that only works if the part’s moving forward relative to the world, and in other cases it just fully passes through.
I don’t have much knowledge on CFrames and Vector3s, but here’s the current code that I’m using:

local function projectileLaunch(projectileName : string, front : BasePart, rotationalVector : Vector3, plrChar : Model, projectileParams : table)
	local excludeFilter = {}
	local newLerpPos
	local lookDirect
	local clonedProjectile : Model = ServerStorage:WaitForChild(projectileName):Clone()
	local hitbox : BasePart = clonedProjectile:WaitForChild("Hitbox")
	clonedProjectile.Parent = game.Workspace
	clonedProjectile:PivotTo(front.CFrame * CFrame.new(front.CFrame.LookVector * -5))
	local beginPosition = clonedProjectile:GetPivot()
	lookDirect = clonedProjectile:GetPivot().LookVector
	for i = 1, projectileParams.MaxTargets do
		table.insert(excludeFilter, clonedProjectile)
		local rayParams = RaycastParams.new()
		rayParams.FilterType = Enum.RaycastFilterType.Exclude
		for _, Player in ipairs(Players:GetPlayers()) do
			table.insert(excludeFilter, Player.Character or Player.CharacterAdded:Wait())
		rayParams.FilterDescendantsInstances = excludeFilter
		local rayCasted = game.Workspace:Raycast(clonedProjectile:GetPivot().Position, lookDirect*2000, rayParams)
		if rayCasted then
			--newLerpPos = CFrame.new(rayCasted.Position - Vector3.new(hitbox.Size.X/2, 0, hitbox.Size.Z/2))
			newLerpPos = CFrame.new(rayCasted.Position)
			local mag = (newLerpPos.Position - beginPosition.Position).Magnitude
			for i = 0, 1, (projectileParams.Speed/mag)/60 do
				clonedProjectile:PivotTo(beginPosition:Lerp(newLerpPos, i))
			lookDirect = lookDirect - 2*(lookDirect:Dot(rayCasted.Normal))*rayCasted.Normal
			beginPosition = newLerpPos
	Debris:AddItem(clonedProjectile, 0)
1 Like

Bumping bcuz I really need a solution for this

If your projectile is shaped like a sphere (I’m thinking a grenade or stone or something) you could try using spherecasts instead of raycasts:

From what I know of them they’re like raycasts except they take volume into account.


My projectile is more of a cylinder, although I can perhaps play with the parameters until I can get it working, I’m busy atm but I’ll update when I can test it

I’m working with Shapecast atm learning how to, and I’m trying to make shape casts for

  • Cylinder
  • Cresents
  • Rings
  • Cones

I’m struggling to get results from the casts atm but just letting u know its possible

If its only the bounce, then try setting the elasticity to its max, which should be 1 in the custom physical properties, if i say something completely out of context then im sorry.

How it looks like for me:

Did some work with the shapecasts and thankfully they work as intended, the max limit of 1024 is frustrating but I’m sure I can find a solution for that