OiiTaru
(OiiTaru)
February 28, 2021, 2:39pm
#1
I’m working on a projectile that Zig-zags during it’s motion;
Below is an example of a :TweenService() version of this -
I’m attempting to do this but using Heartbeat as the main connection.
The projectile works by getting it’s StartPos and pointing towards the Mouse.Hit.p; then from this the Part will move forward using .CFrame.LookVector - Using this information, how can I create zig zag effect similar to that of below?
local TweenService = game:GetService("TweenService")
local Part = workspace.Part
local PointA = Vector3.new(0, 0, 0)
local PointB = Vector3.new(0, 50, 0)
local Dist = (PointA - PointB).magnitude -- The distance between PointA and PointB
local TotalPoints = 10 -- The number of of times you want the projectile to "zig-zag"
local MaxOffset = 10 -- The max offset of each point in studs
local Duration = 0.25 -- The duration of the interpolation between each point
local Info = TweenInfo.new(Duration, Enum.EasingStyle.Linear)
-- Set the parts initial cframe to be at PointA
Part.CFrame = CFrame.new(PointA)
for i = 1, TotalPoints do
-- First get the point on the linear path
local pointCF = CFrame.new(PointA, PointB) * CFrame.new(0, 0, -Dist * (i / (TotalPoints + 1)))
-- Calculate the offset of the point from the path
local offset = CFrame.new(math.random() * MaxOffset, math.random() * MaxOffset, 0)
-- Apply the offset to the point cframe
local finalPointCF = pointCF * offset
-- Move the part towards the final point cframe
local tween = TweenService:Create(Part, Info, {CFrame = finalPointCF})
tween:Play()
wait(Duration)
end
-- And finally, move the part towards the ending position
local tween = TweenService:Create(Part, Info, {CFrame = CFrame.new(PointB)})
tween:Play()
3 Likes
ifkpop
(ifkpop)
June 22, 2022, 11:53pm
#6
Sorry for the late reply, it showed up in “Latest” (strange), but I think you might find this useful:
Need Help with Raycast Projectiles - Help and Feedback / Scripting Support - DevForum | Roblox
1 Like