Currently working on my Wand system - In doing so, I’m hoping to have the spells create a ‘trail’ for the projectile. However, using the basic ROBLOX ones creates just a single line - Is there any way to code the attachments in different directions to give off a ‘Zig zag’ effect?
Ahh okay. Well in that case, rather than making the projectile follow the linear path between the starting point and the finish point, I would calculate random offsets along the linear path to make projectile move in a zig-zag fashion. That should give you the desired zig-zag effect.
I drew a quick illustration to help you get a better understanding. Let me know if you need help with putting it into code!
Thanks for putting that into visual for me!
And yes, I would be extremely grateful - I was going to use a ‘While true do’ to move the attachments around in different directions but that may be more helpful.
Currently the projectile travels through the use of:
for i = 1,100 do wait()
Spell.CFrame = CFrame.new(Spell.CFrame.p + Spell.CFrame.LookVector * 2)
end
Try working with the Trail.WidthScale. By manipulating the NumberSequence you can achieve an easy zigzag using trails. Does not require moving part or attachments.
Before implementing the offset method, I think you should change the way you make the projectile move. Are you trying to make the projectile fly from the wand to where the player clicks?
If you intend for the projectile to travel in a straight line and only the trail to zig zag you can change the trail’s texture to an image that zigzags and tiles seamlessly.
Personally I would prefer going with method I proposed. It’s really not that hard to implement and you don’t have to worry about getting the texture right.
Alright, I’ll give you a simple demonstration. Lets say you want the a part to move from PointA to pointB. You would do it like this (I used TweenService to move the part in this example):
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()
Please read the New Member FAQ to learn how to get a thread created in Platform Feedback, Learning Resources or another category that you are unable to post in. The information you require is available there. Furthermore, try staying on-topic.
@OP If your question has been solved, please mark the post that solved your question as the solution, so others can access this with ease and see what it is that solves the problem.