I tried seemingly everything, The pages i found about this subject did not give a very good explanation. Can someone explain to me how to achieve this? I cant find any quality sources to help me out. And it appears I have been working on this for over 6 hours now, its driving me insane because I don’t know what else to do.
Code:
local Bow = script.Parent.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Target
local Range = 500
Mouse.Button1Down:Connect(function()
local MouseRay = Mouse.UnitRay
local Current = Bow.Handle.Position
local Goal = MouseRay.Direction
for Num = 0, Range do
local RayCast = Ray.new(Current, Goal * Num)
local Ingore = {Player.Character}
local Hit, Pos = workspace:FindPartOnRayWithIgnoreList(RayCast, Ingore)
local NewPos = Current + (10 * Goal) - Vector3.new(0, .5, 0)
Current = NewPos
if Hit then
Bow.DMG:FireServer(Hit.Parent)
break
end
end
end)
Hi!
I know this is an old topic but better late than never!
The script you provided works as you intended, assuming you put it in a local script inside a tool. You may be having trouble with the remote event.
However, I must raise my concern that Projectile Trajectories usually follow the path of an Exponential function rather than a straight line.
To fix this I suggest using this code
local NewPos = Current + (10 * Goal) - (Vector3.new(0, math.pow(1.005,Num), 0) - Vector3.new(0,1,0) )
in place of
local NewPos = Current + (10 * Goal) - Vector3.new(0, .5, 0)
You can also change the numbers inside of the math.pow function to your liking.