Recently I’ve been interested in making some realistic bows! After a few minutes I realized that the only way I could think of shooting arrows didn’t look the best.
I want the arrows to go in an arch instead of facing the same direction throughout its flight. How would I go about doing this??
Here’s my current code:
local arrow = Instance.new("Part")
arrow.Size = Vector3.new(0.5, 0.5, 2)
arrow.Name = "Arrow"
arrow.CanCollide = false
arrow.BrickColor = BrickColor.new("Really red")
arrow.Parent = workspace
arrow.CFrame = script.Parent.CFrame
local velocity = Instance.new("BodyVelocity")
velocity.MaxForce = Vector3.new(100000, 100000, 100000)
velocity.Velocity = arrow.CFrame.LookVector * Vector3.new(50, 50, 50)
velocity.Parent = arrow
wait(0.1)
velocity:Destroy()
arrow.Touched:Connect(function(hit)
if hit ~= script.Parent then
local weld = Instance.new("WeldConstraint")
weld.Part0 = arrow
weld.Part1 = hit
weld.Parent = arrow
end
end)
When I made my bows way back when, I had to pretty much code the trajectory.
To do this you can definitely use recursion and raycasting.
Something like this
local function moveArrow(arrow, speed)
local angle = arrow.Orientation.Y > 10 and CFrame.Angles(0, math.rad(5), 0)
arrow.CFrame = arrow.CFrame * CFrame.new(0,0,speed) * angle
local raycastHit -- code needs to be completed
if raycastHit then
arrow:Destroy()
if raycastHit.Parent:FindFirstChild("Humanoid") then
raycastHit.Parent:FindFirstChild("Humanoid").Health -= 30
end
else
wait(.1)
moveArrow(arrow, speed)
end
end