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()
	print(projectileParams)
	lookDirect = clonedProjectile:GetPivot().LookVector
	for i = 1, projectileParams.MaxTargets do
		print(lookDirect)
		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())
		end
		rayParams.FilterDescendantsInstances = excludeFilter
		local rayCasted = game.Workspace:Raycast(clonedProjectile:GetPivot().Position, lookDirect*2000, rayParams)
		if rayCasted then
			print(rayCasted.Instance)
			print(rayCasted.Instance.Parent)
			--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))
				task.wait()
			end
			lookDirect = lookDirect - 2*(lookDirect:Dot(rayCasted.Normal))*rayCasted.Normal
			beginPosition = newLerpPos
		end
		table.clear(excludeFilter)
	end
	Debris:AddItem(clonedProjectile, 0)
end
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.

2 Likes

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:
https://gyazo.com/3630705efee43cfcbb119bacd94cf7d6

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

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.