So I'm making a Nuke that basically launches from a underground silo and travels across the map but I want it to arc and then after a certain point in the arc start losing lift and start coming down and eventually hitting the ground but I can't seem to get it right and my code is an absolute mess..
basically when its a 1000 studs in the air I want that to be the max height of the rocket I couldn't figure out the calculation of the arc/parabola so I was hoping somebody could help me optimize this script and make it work (btw this script goes with a click detector)
local missile = game.Workspace.Nuke.Missile
script.Parent.ClickDetector.MouseClick:connect(function()
missile.Anchored = false
game.Workspace.Nuke.Part.Smoke.Enabled = true
game.Workspace.Nuke.Part.Fire.Enabled = true
wait(1)
repeat
missile.BodyVelocity.velocity = missile.BodyVelocity.velocity + Vector3.new(0,10,0)
wait(0.5)
until missile.BodyVelocity.Velocity == Vector3.new(0, 500, 0)
end)
script.Parent.Go.Changed:connect(function()
if script.Parent.Go.Value == true then
missile.Anchored = false
game.Workspace.Nuke.Part.Smoke.Enabled = true
game.Workspace.Nuke.Part.Fire.Enabled = true
wait(1)
repeat
missile.BodyVelocity.velocity = missile.BodyVelocity.velocity + Vector3.new(0, 10, 0)
if missile.Position.Y > 20 then
missile.BodyVelocity.velocity = missile.BodyVelocity.velocity - Vector3.new(0, 0, -10)
missile.Rotation = missile.Rotation - Vector3.new(-2, 0, 0)
else
end
wait(0.5)
until missile.Position.Y > 1000
end
end)
while wait(0.1) do
if missile.Position.Y > 1000 then
repeat
missile.BodyVelocity.velocity = missile.BodyVelocity.velocity - Vector3.new(0, 10,0)
missile.Rotation = missile.Rotation - Vector3.new(-2, 0, 0)
until missile.Rotation.X >= -180
end
if missile.Rotation.X >= 180 then
missile.BodyVelocity.velocity.Z = 0
repeat
missile.BodyVelocity.velocity = missile.BodyVelocity.velocity - Vector3.new(0, 50, 0)
until missile.BodyVelocity.velocity == Vector3.new(0, 0, 0)
end
end

1 comment
I'm guessing you're going to have to use lerp for this. I don't know how to do it personally, but there are references online for it.