Using shapecasts for large fast moving projectiles

I have this mostly working, however it doesn’t seem to be good 100% of the time. I’m mostly just wondering if there’s something I’ve forgot to add, or if some of my math is wrong.

Shapecasting:

local range = (script.Parent.Position - lastPosition).Magnitude
	local damage = script.Parent.Damage.Value
	local headshotMultiplier = 2
	local bodyshotMultiplier = 1
	local armshotMultiplier = 0.7
	local legshotMultiplier = 0.8
	local footshotMultipler = 0.15

	local arms = {"RightUpperArm","RightLowerArm","RightHand","LeftUpperArm","LeftLowerArm","LeftHand"}
	local legs = {"RightUpperLeg","RightLowerLeg","LeftUpperLeg","LeftLowerLeg"}
	local feet = {"RightFoot","LeftFoot"}
	
	local ig = {player.Character,workspace.Lasers:GetDescendants(),workspace.HitEffects:GetDescendants()}
	local size = Vector3.new(1,1,1.7)
	local paramaters = RaycastParams.new()
	paramaters.FilterType = Enum.RaycastFilterType.Exclude
	paramaters.FilterDescendantsInstances = ig
	local rR = workspace:Blockcast(lastCF,size,lastCF.LookVector * range,paramaters)

Updating the position and firing the shapecast

RS.Stepped:Connect(function(delta)
	lastPosition = projectile.Position
	lastCF = projectile.CFrame
end)
RS.PostSimulation:Connect(function(delta)
	shapeCast()
end)

EXTRA INFORMATION: The projectile is moved via a BodyVelocity (I know it’s deprecated Linear Velocity isn’t producing good results), the projectile is instantiated on the server, and whoever fired the projectile is set as the networkOwner.

Like I said it works most of the time, but not all the time; I have a feeling it may be due to roblox physics? Or maybe I should move the movement of the projectile entirely to the client and replicate it between clients…

How big is the projectile shapecast in studs?
How thick are the parts being hit? Try shooting at thin parts compared to thick ones and see if that’s the issue.
How fast are these moving? If they are moving at 20 studs/second you’ll have issues with them ‘skipping’ through targets.

You could try using a longer shapecast Part. Say your bullet is 1x3x1 studs. Make your shapecast Part 1x10x1 and have the front face of it lined up with the front face of your bullet so you don’t get false hits. If the trailing part of the shapecast hits the object then you know the front went through it.

Thanks for the quick reply, the shapecasts are currently (1,1,1.7) so a stud thick and ~2 studs long. I initially had them smaller but hit reg was even worse. I’m not sure exactly how I’m supposed to get the studs per second of my projectiles, but the body velocity is as follows:

BV.Velocity = mouse.LookVector * speed --Speed is dependant on the weapon firing but it's generally 1000

I would imagine my projectiles are moving faster than 20 studs per second. I’ll quickly give making the shapecasts longer a shot, and I’ll shot at some thin walls and some thick walls.

Edit: I believe my projectiles might also be rotating in the air? as occasionally the bullet hole will be wildly off from where the projectile visually went.

1 Like