Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is the best way to make a projectile move in an arch shape, and reach the target?

Asked by 5 years ago

Title. I have been trying to script a mortar, and it actually works fine, until you move its height up or down. This has been bugging me because when I will actually use the mortar you could move it up or down.

local mag = ((script.Parent.PrimaryPart.Position-target.Position)-Vector3.new(script.Parent.PrimaryPart.Position.Y,0,script.Parent.PrimaryPart.Position.Y)).magnitude
--shell.vel.Velocity = script.Parent.PrimaryPart.CFrame.lookVector*32.5+Vector3.new(0,50,0)
shell.vel.Velocity = (script.Parent.PrimaryPart.CFrame.lookVector*mag+Vector3.new(0,50,0))
shell.Touched:Connect(function(hit)
    if hit.Parent ~= script.Parent then
    shell:Destroy()
    end
end)
game:GetService("Debris"):AddItem(shell,3)
--wait(.25)
--if shell ~= nil and shell:FindFirstChild("vel") ~= nil then shell.vel:Destroy() end
for i = 1,20 do
    shell.vel.Velocity = shell.vel.Velocity + Vector3.new(0,-2.5,0)
    wait()
end
for i = 1,10 do
    shell.vel.Velocity = shell.vel.Velocity + Vector3.new(0,-5,0)
    wait()
end

(This is a shortened version of the script, most of it is just creating the shell)

I'm not sure how I could calculate a height mechanism to change how high and fast it will go.

0
I wrote up an explanation on the maths of predicting projectiles here a while ago https://scriptinghelpers.org/questions/50122/how-would-i-go-about-predicting-where-an-object-would-land#50005. You can probably use it to derive any equation you'd need, although the maths might get a bit spicy. fredfishy 833 — 5y

Answer this question