Working with trails?

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?

Thanking you,

5 Likes

How are you currently achieving this single line effect? Are you using the trail effect or beams?

Trail, edited to give off the fading effect as the projectile travels as I couldn’t achieve this with a beam

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!
26%20PM

3 Likes

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.

you can read about WidthScale here.

hope this helps

1 Like

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.

Wouldn’t that just make the trail be straight with random widths along the path like this?

1 Like

Yes, but if you made the texture transparent on one side then it would work

Yea but the texture would still be stretched and wont be the best quality

I guess :man_shrugging:

but its easier than moving the attachments or accessories

One thought: if you made the zigzag a well-tiled trail texture, which could look really clean and nice, since trails are procedural in that sense

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.

I don’t think I quite understood your method, could you explain it?

how would you go about implementing this?

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()

And here’s how it should turn out:

Image from Gyazo

19 Likes

dang, this was well thought out!

great job!

Edit: Perhaps you could make this a tutorial?

1 Like

Thanks! :slight_smile:

I can’t post in the Learning Resources section yet since I’m still the New Member rank. It’s only Members+ I think.

You can post in the learning resource

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.

1 Like