Hello.
I have a working battleship turret script.
However, the shells shoot straight instead of in an arc. The shell’s code is to simply move at their LookVector at 500 studs per second.
However, I want the shells to curve up then crash down on the target.
Here is my turret code.
wait(3.1)
local ship = script.Parent.Parent.Parent.Parent
if ship.Parent == workspace.RedShips then
targets = workspace.BlueShips
bull = game:GetService("ReplicatedStorage").RedShell
end
if ship.Parent == workspace.BlueShips then
targets = workspace.RedShips
bull = game:GetService("ReplicatedStorage").BlueShell
end
local function getTarget()
local targetVal = script.Parent.Target.Value
for i,v in pairs(targets:GetChildren()) do
if v.Name == targetVal then
target = v
end
end
return target
end
local function FireGuns(angle)
for i,v in pairs(script.Parent:GetChildren()) do
if v.Name == "BulletPos" then
local bullet = bull:Clone()
bullet.Orientation = script.Parent.Orientation
bullet.Position = v.WorldPosition
bullet.Parent = workspace
v.Boom:Play()
end
end
end
local orientationPart = game:GetService("ReplicatedStorage").OrientationHack
local function FindAngle(target)
local origincframe = ship.ShipEngine.BodyGyro.cframe
local dir = (ship.PrimaryPart.Position - target.PrimaryPart.Position).unit
local spawnPos = ship.PrimaryPart.Position
local pos = spawnPos + dir
orientationPart.CFrame = CFrame.new(pos, pos+dir)
script.Parent.Orientation = orientationPart.Orientation
end
while wait(math.random(30,50)) do
local target = getTarget()
if target then
FindAngle(target)
FireGuns()
end
end