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