Detecting Air as a hitboc

Problem

So I am making artillery for a game I am working on. It simply works out a force to push a part(sphere) from get it from A to B and then pushes it.

When I click F8 and run it, it all works fine.

However, when I click “Play here” the sphere seems to detect hitting something mid-air.

I currently think that Roblox is just being Roblox but here is the script and explorer:

image

local cannon = script.Parent.Parent.Parent.Parent
local pos1 = cannon.Start.Position
local pos2 = cannon.End.Position
local dir = pos2 - pos1
local dur = math.log(1.001 + dir.Magnitude * 0.01)
local force = dir/dur + Vector3.new(0, game.Workspace.Gravity * dur * 0.5, 0)

local clone = game.ReplicatedStorage.ArtyShell

while wait(6) do
	local artShell = clone:Clone()
	artShell.Position = pos1
	artShell.Parent = workspace
	artShell:ApplyImpulse(force * clone.AssemblyMass)
	artShell:SetNetworkOwner(nil)
	
	artShell.Touched:Connect(function(hit)
		if hit.Transparency == 1 or hit:IsDescendantOf(cannon) then return end
		artShell.Size *= Vector3.new(2,2,2)
		artShell.Anchored = true
		print(hit.Name)
		game.Debris:AddItem(artShell, .5)
		local ts = game:GetService("TweenService")
		local ti = TweenInfo.new(.5, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
		local goal = {Transparency = 1}
		local tween = ts:Create(artShell, ti, goal)
		tween:Play()
		
		if hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent:FindFirstChild("Humanoid").Health -= 50
		end
	end)
end

If you see the problem, any help is appreciated.

You are using physics and they’re unreliable for something like projectiles for the most part. You might want to use differemnt method or something.

could you try seeing if it still looks that way in “play here” when you switch from client view to server view?

if the above is false, and it looks fine on server view, then this is most likely a replication issue.

also, is it actually not hitting something? what did it print?

It prints “Part” which is the confusing thing because going back into editor and looking at it, there aren’t any parts there. But it only happens whilst a player is in.

I would add more debugging print statements to get more information about what is being hit.

Then, based on what is being hit, either remove the stuff getting in the way or add another if () then return end to filter it out.

do print(hit:GetFullName())
lmk the results, if you have a part thats needed in the way try setting the parts cantouch property to false

It’s probably hitting the “Part” as it printed.

Visually for you it seems it’s just disappearing before hitting the ground, but it actually hits it. Try setting the network owner to the server and see if that fixes it for you.

Alternatively, don’t use physics, use something like fastcast or an updated version of such if you want precision.

Yeah. We kept going with it by adding craters wherever it landed; the craters all appeared where they would have landed. It was hitting the part just not visually.

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