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

How do I make a projectile go in an arc?

Asked by
xEiffel 280 Moderation Voter
5 years ago

Hi, thanks for reading!

I am struggling with how to make a projectile go in an arc; I was following a tutorial on the dev forum but can't quite figure out how to modify the speed on it.

https://devforum.roblox.com/t/modeling-a-projectiles-motion/176677

local t = 0.5;
local mouse = game.Players.LocalPlayer:GetMouse();
local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart");
local bball = script.Parent:WaitForChild("Handle");

mouse.Button1Down:Connect(function()
    local g = Vector3.new(0, -game.Workspace.Gravity, 0);
    local x0 = hrp.CFrame * Vector3.new(0, 2, -2)

    -- calculate the v0 needed to reach mouse.Hit.p
    local v0 = (mouse.Hit.p - x0 - 0.5*g*t*t)/t; -- The 0.5 tracks distance travelled

    -- have the ball travel that path
    local c = bball:Clone();
    c.Velocity = v0;
    c.CFrame = CFrame.new(x0);
    c.CanCollide = true;
    c.Parent = game.Workspace;
end)

I was wondering if anyone knew how to do it an easier way, and If you can do it w/ BodyForces and how.

Thanks!

0
I was going through a script made for Void Script Builder, and it was a magic script. One of the moves had a fireball shoot in an arc by first setting the cframe of its fireball to the Mouse Position, and then the cframe changed by adding a cframe of CFrame.new(0,0,-4) to the fireballs CFrame in a for i loop ScrubSadmir 200 — 5y

1 answer

Log in to vote
2
Answered by
EgoMoose 802 Moderation Voter
5 years ago
Edited 5 years ago

Hi there, I wrote that post so hopefully I can clear up any confusion.

The best way to modify the speed is to to lower the time value t as it represents the time it takes for the object to reach its target. Of course because we are using physics here the trade-off for this is that the object will take a more direct path and the arc will not be as pronounced.

If you are attempting to travel a pronounced arc very quickly you likely do not want to use the built in physics. Instead you should be setting the CFrame every frame (which is also covered in that post).

0
lol the writer answers op's question User#19524 175 — 5y
0
Thanks, sorry for the late reply! xEiffel 280 — 5y
Ad

Answer this question