(SOLVED BY SELF!) Hello! I am trying to make a throwing system and I want my throwing system to allow the projectile to go for example 50 studs maximum. I slightly modified EgoMoose's Modeling projectile motion script which can be found Here. As it stands, my current code is :
local t = 1; local mouse = game.Players.LocalPlayer:GetMouse(); local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart"); local bball = script.Parent mouse.Button1Down:Connect(function() if script.Parent.Parent.Parent ~= workspace then local g = Vector3.new(0, -game.Workspace.Gravity, 0); local x0 = hrp.CFrame * Vector3.new(0, 2, -2) local pos = mouse.Hit.p if (hrp.Position - pos).magnitude > 50 then --this is to make sure it does not travel more than 50 studs --im guessing the code to make it go 50 would go here. else local v0 = (pos - x0 - 0.5*g*t*t)/t; local c = bball:Clone(); c.Velocity = v0; c.CFrame = CFrame.new(x0); c.CanCollide = true; c.Parent = game.Workspace; end end end)
This limits the distance, however I don't know how to make it just go that distance. Any help is appreciated. Thanks, BrainDead_Dev.
Edit : I tried something else today and still not working. What I tried :
local t = 1; local mouse = game.Players.LocalPlayer:GetMouse(); local hrp = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("HumanoidRootPart"); local bball = script.Parent mouse.Button1Down:Connect(function() if script.Parent.Parent.Parent:FindFirstChild("Humanoid") then local g = Vector3.new(0, -game.Workspace.Gravity, 0); local x0 = hrp.CFrame * Vector3.new(0, 2, -2) local pos = mouse.Hit.p if (hrp.Position - pos).magnitude > 50 then local offset = Vector3.new(0,0,50) pos = hrp.CFrame * offset end local v0 = (pos - x0 - 0.5*g*t*t)/t; local c = bball; script.Parent.Parent.qPerfectionWeld.Disabled = true c.qCFrameWeldThingy:Destroy() c.CanCollide = true; c.Parent = game.Workspace; c.Velocity = v0; c.CFrame = CFrame.new(x0); c.Anchored = true end end)
SOLUTION : First I made a part constantly be in front of me, and then I set pos to that parts position. Simple as that