Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a rocket arc with bodyvelocity?

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..

place

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

0

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.

1 answer

✓ Accepted answer

So I experimented around a bit and this is what I came up with:

ply = game.Players.LocalPlayer
mouse = ply:GetMouse()
go = false

function Berp()
	game.Workspace.CurrentCamera.CameraSubject = game.Workspace.Part
	for i = 0,45 do
		game.Workspace.Part.BodyVelocity.Velocity = game.Workspace.Part.CFrame.lookVector * 300
		game.Workspace.Part.Rotation = Vector3.new(i,0,0)
		wait(0.05)
	end
	for i = 45,-45,-1 do
		game.Workspace.Part.BodyVelocity.Velocity = game.Workspace.Part.CFrame.lookVector * 300
		game.Workspace.Part.Rotation = Vector3.new(i,0,0)
		wait(0.05)
	end
end

mouse.Button1Down:connect(Berp)

This just serves as an example and I'm sure there's a more effective way of doing this.

2 comments

0

thanks!

0

I made a script where a part moved in a circular motion, but can't remember what placed I put it in. Anyway this is ineffective when it comes to dealing with rotated parts so I'll work on a new script just for the kicks.

This discussion is preserved as it was. New answers, comments, and votes are closed.