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

How do I make this trajectory script end exactly where my mouse is?

Asked by 5 years ago

Hello

I am working on a paint gun for my upcoming game, I adjusted a script I found on the Dev Forum that shows the trajectory of the paint that will come out of the gun. Here is the function that creates the trajectory

local function Beam_Func()
    local part
    if player.Character then
        local upperTorso = player.Character:FindFirstChild("UpperTorso")
        if upperTorso then
            part = upperTorso
        end
    end
    local mouse = game.Players.LocalPlayer:GetMouse()
    local disp = (mouse.Hit.p - part.Position)
    local mag = math.min(script.Parent.radius.Value, disp.Magnitude)
    local pos = disp.Unit * mag + part.Position

    local X0 = startPoint.CFrame.Position
    local V0 = (pos - X0 - 0.5*Gravity*T*T)/T

    local Curve0, Curve1, CF1, CF2 = BeamProjectile_Func(V0, X0, T)
    Beam.CurveSize0 = Curve0
    Beam.CurveSize1 = Curve1

    Attach0.CFrame = Attach0.Parent.CFrame:inverse() * CF1
    Attach1.CFrame = Attach1.Parent.CFrame:inverse() * CF2
end

Here is what I’m trying to achieve, I want the trajectory to end exactly where the mouse is, but the problem is that the trajectory ends on the max radius of 25 on the pathway to where the mouse hits. The problem is that this can create some weird trajectories

Here's a picture that shows what is happening and the drawn arrows is what I want.

Picture

If I need to elaborate on anything else, please let me know. Thanks.

Answer this question