Recently, I've been learning how to script, and so I decided to make a simple cannon that fires whenever you press a trigger block. The problem is, I want the velocity of the cannonball that it launches to always be towards the direction of the muzzle. How do I go about doing this? Or is there a more efficient method?
gun = game.Workspace.Cannon
trigger = game.Workspace.Trigger
db = false
function fire()
if gun == nil then return end
if db == false then
db = true
local projectile = Instance.new("Part")
trigger.BrickColor = BrickColor.new(1004)
projectile.Position = gun.Position
projectile.BrickColor = BrickColor.new(1003)
projectile.Shape = "Ball"
projectile.Size = Vector3.new(3,3,3)
projectile.Material = "Metal"
projectile.Name = "Cannonball"
projectile.CanCollide = false
projectile.Velocity = ???
projectile.Parent = game.Workspace
wait(5)
trigger.BrickColor = BrickColor.new(1020)
db = false
end
end
script.Parent.Touched:connect(fire)

2 comments
Thanks for the help! I need to think like that more often.
If this answered your question, please mark it as the answer!