BodyVelocity lagging through walls

I am currently making a hockey game using BodyVelocity as the main mechanic for shooting and have encountered a bug that you can shoot through the net and score a goal or shoot through the arena.

Here’s the server script code involving the bodyvelocity.

script.Parent.Equipped:Connect(function()
	script.Parent.SE.OnServerEvent:Connect(function(plr,power,mhp,mhv) -- plr = the player, power = number from 1-100 on how fast the puck shoots, mhp = mouse hit position, and mhv = mouse hitvector
		local force = Instance.new("BodyVelocity")
		force.MaxForce = Vector3.new(1,1,1) * math.huge
		local power2 = power
		if power >= 60 then
			local test1 = mhv * power2
			local test2 = test1 + Vector3.new(0,power / 5, 0)
			force.Velocity = test2
		else
			force.Velocity = mhv * power2
		end
		force.P = math.huge 
		game.Workspace.Puck.Canpick.Value = false -- Seperate thing.
		game.Workspace.Puck:FindFirstChild("Attatched"):Destroy() -- Seperate thing.
		game.Workspace.Puck.CFrame = CFrame.lookAt(game.Workspace.Puck.Position, mhv)
		game.Workspace.Puck.CanCollide = true
		force.Parent = game.Workspace.Puck
		game:GetService("Debris"):AddItem(force, power / 100)
		wait(.75)
		game.Workspace.Puck.Canpick.Value = true -- Seperate thing.
	end)
end)

Here is a clip of the puck going through the net when shot.

The Roblox “physics engine” doesn’t like to obey the laws of physics, such as the laws that govern geometric clipping. Objects with high velocity tend to no-clip through thin walls or floors.

Barriers:
To fix this, you could create invisible barriers on the sides of the net. You might want to look into collision filtering.

Hitboxes:
However, if you decide not to change the hitbox of the net, you can always change the hitbox of the puck. Using a RigidConstraint or a WeldConstraint to attach a transparent cylinder encapsulating the entire puck’s hitbox could resolve the issue.

Raycasting:
Or, you could set up a heartbeat function that casts a ray towards the direction of motion every frame. When the ray’s magnitude becomes very small you can take the surface normal of the raycast instance and add a repulsive force to the puck.

I hope this helps! :slight_smile: