Curving Battleship Shells

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


Well, you have LookVector. You can just change that vector’s z value.
You can use this formula to change z value:
z = (v * t) - (0.5 * a * t * t)

where v is initial speed, a is acceleration, t is time.
I think, you need to change t (time) every frame/step, and change a (acceleration) every time you want to fire.

2 Likes

Sorry, school started and I’m quite busy. I will try your suggestion on the weekend. :slight_smile: Thanks for helping!

local time = 0
local e = script.Parent.BodyVelocity
local pos = script.Parent
local dir = pos.CFrame.lookVector
delay(45, function()
	script.Parent:Destroy()
end)
e.MaxForce= Vector3.new(math.huge,math.huge,math.huge)
while wait(0.1) do
	time = time + 0.1
	z = (300 * time) - (0.5 * 196.2 * time * time)
	x= script.Parent.CFrame.LookVector.X
	y = script.Parent.CFrame.LookVector.Y
	print(y)
	v = Vector3.new(x, y, z) * 1
	e.velocity = v
end


This is my new code for the bullet-moving script. For some reason, it doesn’t move up at all.
It goes forwards than it goes backward and accelerates. :confused: Do you know what is happening?

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