Hello, I’m having trouble with modeling an arrow’s protectory with beams. I know there’s lots of topics similar to do this. But, I couldn’t find any good answers.
I tried looking at Ego Moose’s tutorial, but it only somewhat worked. Instead of straightening the beam it increased the parabola. I tried doing max - curve0
to no avail. I’m using fast cast.
Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Tool = script.Parent
local handle = Tool:WaitForChild("Handle")
local arrow = Tool:WaitForChild("Arrow")
local bow = Tool:WaitForChild("Bow")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local camera = workspace.CurrentCamera
local beam = script:WaitForChild("Beam")
local endPoint = handle:WaitForChild("EndPoint")
local debounce = false
local cooldown = 0.5
local power = 0
local function beamProjectile(g, v0, x0, t1)
local c = 0.5 * 0.5 * 0.5
local p3 = 0.5 * g * t1 * t1 + v0 * t1 + x0
local p2 = p3 - (g * t1 * t1 + v0 * t1) / 3
local p1 = (c * g * t1 * t1 + 0.5 * v0 * t1 + x0 - c * (x0 + p3)) / (3 * c) - p2
local curve0 = (p1 - x0).Magnitude
local curve1 = (p2 - p3).Magnitude
local b = (x0 - p3).Unit
local r1 = (p1 - x0).Unit
local u1 = r1:Cross(b).Unit
local r2 = (p2 - p3).Unit
local u2 = r2:Cross(b).Unit
b = u1:Cross(r1).Unit
local cf1 = CFrame.new(x0.X, x0.Y, x0.Z, r1.X, u1.X, b.X, r1.Y, u1.Y, b.Y, r1.Z, u1.Z, b.Z)
local cf2 = CFrame.new(p3.X, p3.Y, p3.Z, r2.X, u2.X, b.X, r2.Y, u2.Y, b.Y, r2.Z, u2.Z, b.Z)
return curve0, -curve1, cf1, cf2
end
local function createAndSetBeam(g, v0, x0, endTime)
local t = endTime or 1
local curve0, curve1, cf1, cf2 = beamProjectile(g, v0, x0, t)
local beam, attach0, attach1 = beam, handle.Origin, handle.EndPoint
beam.CurveSize0 = math.clamp(30 - curve0, 0, 30)
beam.CurveSize1 = math.clamp(30 + curve1, -30, 0)
beam.Segments = 10 * math.round(t * 3)
attach0.CFrame = attach0.Parent.CFrame:Inverse() * cf1
attach1.CFrame = attach1.Parent.CFrame:Inverse() * cf2
return beam, attach0, attach1
end
Tool.Activated:Connect(function()
if not debounce then
holding = true
power = 0
task.spawn(function()
repeat task.wait(0.025)
power = power + 25
until power >= 600 or not holding or not equipped
end)
task.spawn(function()
while true do
local g = Vector3.new(0, -workspace.Gravity, 0)
local t = (power / 600)
local x0 = handle:WaitForChild("Origin").WorldPosition
local v0 = (mouse.Hit.Position - x0 - 0.5 * g)
createAndSetBeam(g, v0, x0, t)
task.wait(0.01)
end
end)
end
end)
For reference I want something like bed wars. I found a topic, but it only covered the fast cast part not the actual trajectory.
Thank you.