What I’m trying to do is have a SurfaceGUI on a conveyor belt part that shows an Arrow/Arrows pointing and scrolling towards the same direction as the conveyor belts direction.
(I turned off Clipping to show how i want it to work)
The rotation of the image is working perfectly fine. The biggest issue I’m having is with the scrolling movement of the Arrow. I thought this would be easy for but but I’ve been trying to figure this out for days and I could never get it working properly.
I was able to get it working fine if the direction of the conveyor is in a single direction. When the conveyor is set to 2 directions though, it starts to not work as expected.
To set the position of the image, I’m using both the Position and the Anchor point to ensure that the ImageLabel reaches the exact edge of the UI before looping again if that makes sense.
Also, I’m using a Coroutine because I’m intending to apply this effect to multiple conveyor parts.
local Texture = RS.Arrows:Clone()
local Direction = part.AssemblyLinearVelocity.Unit
local NewDirection = Vector3.new(Direction.Z,Direction.Y,Direction.X) --switch around direction to match same direction as image
local _,RotY,_ = (CFrame.lookAt(part.Position,part.Position+(NewDirection*5))):ToOrientation() -- Get Rotation of the direction
local Image:ImageLabel = Texture.ClipFix.Image
Texture.Parent = part
Image.Rotation = math.deg(RotY) -- Set rotation of image to face direction
Image.Size = UDim2.new(1,500+(math.abs(RotY)*(700/630)),1,700-(math.abs(RotY)*(700/630))) -- Changes ImageLable size in accordance with the rotation.
coroutine.wrap(function()
local arrowSpeed = 0.01
-- Formulas i came up with:
-- (Direction+1)/2 : Shorten direction from (1 to -1) to (1 to 0)
-- Direction+(-Direction*Offset) : Direction to 0
-- Direction*Offset : 0 to Direction
while true do -- Move Image into the direction of Conveyor belt
local ShortPos = Vector2.new((NewDirection.X+1)/2,(NewDirection.Z+1)/2)
for Offset = 0,1,arrowSpeed do
local FinalPos = Vector2.new(ShortPos.X*Offset, ShortPos.Y+(-ShortPos.Y*Offset))
Image.Position = UDim2.fromScale(FinalPos.X,FinalPos.Y)
Image.AnchorPoint = FinalPos
end
end
end)()
Let me know how I can improve or make this work better! If you have any questions, feel free to ask me and i will try to answer the best of my knowledge.