PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

TextureMode

Trail

TextureMode

A Trail’s TextureMode property determines how the effect’s Trail/Texture (if any) is drawn. The behavior of the texture in each mode is also very much dependent on the effect’s Trail/TextureLength property. Note that changing an effect’s TextureMode after some of the trail has been drawn will affect all of the previously drawn segments.

TextureMode defaults to Stretch

##Stretch
Stretch is the default TextureMode for Trails. In this mode the texture will be tiled a number of times equal to the number defined by TextureLength. It will stretch these tiles evenly to fit the entire length of the drawn trail. For example, if TextureLength is set to 4 then the texture will always repeat 4 times in the trail, no matter how long or short the trail is.

Demonstrating a trail texture using the stretch mode.

##Wrap
In the Wrap mode, the texture will start at the attachment points and will move as the attachments move. As soon as the attachments have moved a number of studs equal to the TextureLength, then the texture will repeat. The longer the trail is, the more times the texture will repeat.

Demonstrating a trail texture using the wrap mode.

##Static
In the Static mode, the texture will start at the initial position of the trail and will be drawn as the attachments move. Once the attachments move a number of studs equal to the TextureLength, then the texture will repeat.

Demonstrating a trail texture using the static mode.


Code Samples


Setting a Trail’s Texture Mode

This example demos setting a trail’s texture mode.

In order to do this, we must first create a BasePart, part, which will be the parent of the trail.

Then, we create two attachments, attachment0 and attachment1, both parented to part. The positions of these two attachments, more importantly the distance between them, determines where the trail is drawn as part moves.

For these attachments to create a trail as described, we create a new Trail and parent it to part. We then connect attachment0 to Trail/Attachment0 and attachment1 to Trail/Attachment1.

In this example, we set the trail’s texture mode to static. Note that this is just one of three possible modes, and that the example below can easily be changed to use another mode. We also set the texture of the trail to a pawprint image.

Finally, to demo the texture mode the example relies on TweenService’s TweenService/Create to move part back and forth. As the part moves, the trail is drawn.

Demonstrating the static trail texture mode.

-- Create a new BasePart
local part = Instance.new("Part")
part.Parent = game.Workspace
part.Anchored = true
part.Position = Vector3.new(0,5,0)

-- Create 2 attachments
local attachment0 = Instance.new("Attachment")
attachment0.Name = "Attachment0"
attachment0.Parent = part
attachment0.Position = Vector3.new(-2,0,0)

local attachment1 = Instance.new("Attachment")
attachment1.Name = "Attachment1"
attachment1.Parent = part
attachment1.Position = Vector3.new(2,0,0)

-- Create a new Trail
local trail = Instance.new("Trail")
trail.Parent = part
trail.Attachment0 = attachment0
trail.Attachment1 = attachment1

-- Set the trail texture and texture mode
local textureId = "rbxassetid://909814149"
trail.Texture = textureId
trail.TextureMode = Enum.TextureMode.Static
trail.TextureLength = 4

-- Tween part to display trail
local TweenService = game:GetService("TweenService")

local dir = 15
while true do
	dir = dir*-1
	local goal = {}
	goal.Position = part.Position + Vector3.new(0,0,dir)
 
	local tweenInfo = TweenInfo.new(5)
	local tween = TweenService:Create(part, tweenInfo, goal)
 	tween:Play()

	wait(5)
end