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

Homing Rocket Launcher Help - Anyone?

Asked by 10 years ago

Hey guys, I'm trying to make a homing rocket launcher. The actual problem is that the second script, the one that's supposed to be moved to the rocket, is not working. The first script used to be smashed too, but I realised I had to make it a localscript. Rocket LAUNCHER Script:

script.Parent.Equipped:connect(function (m)
    m.KeyDown:connect(function (key)
        if key:lower() == "q" then
            local p = m.Target
            if p:IsA("Part") then
                Rocket = Instance.new("Part", game.Workspace)
                Rocket.BrickColor = BrickColor.new("Bright red")
                Rocket.Size = Vector3.new(1,1,4)
                Mesh = script.Parent.Mesh:Clone()
                Mesh.Parent = Rocket
                Rocket.Position = script.Parent.Handle.Position + Vector3.new(0, 3, 0)
                RP = Instance.new("RocketPropulsion", Rocket)
                RP.Target = p
                RP:Fire()
                RP.CartoonFactor = 1
                newScript = script.Explosion:Clone()
                newScript.Parent = Rocket
                newScript.Disabled = false
                RP.MaxThrust = 10000
                RP.MaxSpeed = 1000
            end
        end
    end)
end)

And the script that goes into the ROCKET:

function GetDistance(Object1, Object2)
    return(Object1.Position - Object2.Position).magnitude
end

while true do
    script.Value.Value = (GetDistance(script.Parent, script.Parent.RocketPropulsion.Target))
    if script.Value.Value > 100 then
        script.Parent.RocketPropulsion.MaxSpeed = 250
    elseif script.Value.Value < 100 then
        script.Parent.RocketPropulsion.MaxSpeed = 125
    elseif script.Value.Value < 50 then
        script.Parent.RocketPropulsion.MaxSpeed = 75
    elseif script.Value.Value > 10 then
        script.Parent.RocketPropulsion.MaxSpeed = 25
    elseif script.Value.Value < 10 then
        script.Parent.RocketPropulsion.MaxSpeed = 15
    elseif script.Value.Value == 10 then
        script.Parent.RocketPropulsion.MaxSpeed = 20
    end
    wait(.05)
    script.Parent.Touched:connect(function (hit)
    e = Instance.new("Explosion", hit)
    e.Position = hit.Position
    e.ExplosionType = "CratersAndDebris"
    e.BlastRadius = 10
    script.Parent:Destroy()
end)
end

script.Parent.Touched:connect(function (hit)
    e = Instance.new("Explosion", hit)
    e.Position = hit.Position
    e.ExplosionType = "CratersAndDebris"
    e.BlastRadius = 10
    script.Parent:Destroy()
end)

I'm not sure what I did wrong, so if anyone could tell me that would be great. Thanks in advance.

1 answer

Log in to vote
0
Answered by 10 years ago

In my own experience (trying to develop a similar rocket system right now) the hardest part seems to be picking out the specific player. My idea was to use Mouse.Target to get the torso of the targeted character and then propel the rocket with a toned down BodyPosition. So maybe look over the targeting part a bit more. Also, I don't think you need the repeated "Touched" function inside the while loop, since you already have it outside the loop.

0
Erm, actually I DO need it inside as well as it doesn't run if the loop is running on the same timeframe. SquirreIOnToast 309 — 10y
0
Ah ok. So, does it give you any errors in the Output window? I'm looking at the RocketPropulsion to see how it works. deaththerapy 60 — 10y
0
So I just played around with a simple script to test out how well RocketPropulsion works, and it didn't do anything. the propulsion had a target, and I tweaked the thrust values quite a bit, but it still didn't even stop my character from pushing the rocket over. It could be semi-depricated, so I'd suggest using BodyPosition instead, which will need a loop to update the target position. deaththerapy 60 — 10y
Ad

Answer this question