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:
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
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.
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.