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

How Do I Launch a Projectile Forwards from a Defined Object?

Asked by 9 years ago

Here's my code so far:

Range = (script.Parent.Target.Position - script.Parent.Projectile.Position).magnitude
print(Range)
Degrees = 45
function Calculate(Range, Type, Vector)
    if Type == "Initial Velocity" then
        if Vector == "Y" then
            local Calculation = math.sqrt(Range * 196.2 / math.sin(math.rad(Degrees * 2))) / 2
            return Calculation
        else
            local Calculation = math.sqrt(Range * 196.2 / math.sin(math.rad(Degrees * 2)))
            return Calculation
        end
    end
end

script.Parent.Projectile.Velocity = Vector3.new(Calculate(Range, "Initial Velocity", "X"), Calculate(Range, "Initial Velocity", "Y"), 0)

It calculates exactly how much force needs to be applied to land an object at a coordinate; however it has two problems. It only works on one axis, and not into negative Vector3 locations. I theorised that this would be fixed by finding the distance, and launching outwards after lookVectoring the part. I'm fine with both of these things, however I need help with launching the object to the right place, if say, I put the launch platform at a different horizontal angle.

I need it to launch directly forward of a part, any help and/or advice would be greatly appreciated.

Thanks, SquirrelOnToast

1 answer

Log in to vote
0
Answered by 9 years ago

Oh god, no need for something this complex. Just use a Body Velocity object with a few lines of code. I didn't really understand what you wanted, but if you wanted a projectile to fly forwards from lets say the players Torso, this what you have to do

Make a body velocity object called bv or whatever

bv.maxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.velocity = player.Character.Torso.CFrame.lookVector * speed

You can turn speed into a negative for it to fly backwards.

You are welcome.

0
Looking for it to fly in an arc of 45 degrees, and land on target. Found a piece of gear to help me though, it's called Throwing Axe or something. SquirreIOnToast 309 — 9y
Ad

Answer this question