Explosions acting weird

Hello! I am currently making an A-10 Warthog airstrike in roblox, and I am having troubles with setting the explosions position. I’m using raycasts from the plane to the target to put the explosions there. However, instead of being scattered around-ish but generally in one main area, its completely scattering around. Going up when it shouldn’t, moving 100 studs away, overall its just very weird.

What I want it to look like:

What it actually looks like:

Here is the code in question:

	ray_params.FilterType = Enum.RaycastFilterType.Blacklist
	ray_params.FilterDescendantsInstances = {jet, jet.PrimaryPart}
	
	task.wait(1.45)
	for i = 1, 56 do
		local raycast_result = workspace:Raycast(jet.PrimaryPart.Position, (target.Position - jet.PrimaryPart.Position), ray_params)
		
		if raycast_result then
			local instance = raycast_result.Instance
			local model = instance:FindFirstAncestorOfClass("Model")
			
			--if the ray hit anything
			if (model) or (not model) then
				local hit_pos = raycast_result.Position
				local hit_norm = raycast_result.Normal
				
				--explosion
				local explosion = Instance.new("Explosion", workspace)
				DEBRIS:AddItem(explosion, 4)
				explosion.BlastPressure = 1000000
				explosion.BlastRadius = 1000
				print(instance)
				explosion.ExplosionType = Enum.ExplosionType.Craters
				
				local offset = hit_norm + Vector3.new(math.random(-50, 50), 0, math.random(-50, 50))
				explosion.Position = hit_pos + offset
				
				--destroying parts
				explosion.Hit:Connect(function(part)
					part.Anchored = false
				end)
			end
		end
		task.wait(.025)
	end

Any help will be appreciated :cowboy_hat_face:

Sorry but I had to bump this because I still havent found the answer. I tried using ChatGPT, but it ended up not working :sweat_smile:

I thought I had the solution but its still not working! This is getting very frustrating…

Can you print(hit_norm) to check?

Sure thing! The hit norm seemed to be way off from what the target’s position.

Hit norm: 1.910685465164705e-15, 1, 4.371138828673793e-08

Target’s position: -38.643829345703125, 0, -29.77405548095703

To add to that, the raycast result’s position matched with the targets position. This is really weird, I dont know why its not working :slightly_frowning_face:

I found the fix to it! Apparently, it had something to do with the target/jet being nil.

1 Like

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