local barrel = script.Parent
local fired = script.Parent.fired
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CannonBall = ReplicatedStorage:WaitForChild("CannonBall")
local Explosion = ReplicatedStorage:WaitForChild("Explosion")
local cooldown = 7
local speed = 100
local exploded = false
local function fire()
exploded = false
local CannonBallClone = CannonBall:Clone()
CannonBallClone.Parent = game.Workspace
CannonBallClone.Position = barrel.Position
fired:Play()
CannonBallClone.AssemblyLinearVelocity = barrel.CFrame.LookVector * speed
local function explode()
local Explosion = Instance.new("Explosion")
Explosion.Parent = game.Workspace
Explosion.Position = CannonBallClone.Position
wait(0.1)
CannonBallClone:Destroy()
end
CannonBallClone.Touched:Connect(function(hit)
print("Touched!")
if exploded == false then
explode()
exploded = true
end
end)
wait(cooldown) -- Explodes after a certain time if cannon ball is untouched
if exploded == false then
explode()
exploded = true
end
end
while wait(1) do
fire()
end
It doesn’t look like anything is wrong, just that the projectile is obeying gravity. (You don’t have a force applied to the cannonball that counteracts gravity)
If you want your cannonball to have gravity, maybe tilt it up like 45 degrees upwards
I would use TweenService to move the cannonball towards where you want it to go. It’s more adjustable and smoother. You’ll be able to anchor the cannonball and still have it move.
Most likely, your problem is that the cannonball may be touching itself (if you have other parts inside it), or the cannonball launcher. Use a whitelist system to make sure the cannonball is not touching itself or the cannon.
CannonBallClone.Touched:Connect(function(hit)
if exploded == false and hit == "Baseplate" then --modify
explode()
exploded = true
end
end)
This appears to be the issue because when I disabled the exploding and destroy function, it hit the ground around that spot. How do I add a force that contracts gravity?