Advertisement
blakehelton

Moving Platform Script

Jul 29th, 2021
1,283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.62 KB | None | 0 0
  1. local axis = "x"
  2. local distance = 50
  3. local speed = 1
  4.  
  5. local factor = 0
  6. local initialPosition = script.Parent.CFrame.Position
  7. local moveDirection = Vector3.new(
  8.     axis == "x" and distance or 0,
  9.     axis == "y" and distance or 0,
  10.     axis == "z" and distance or 0
  11. )
  12. local destinationPosition = initialPosition + moveDirection
  13. local RunService = game:GetService("RunService")
  14. function movePlatform (time, step)
  15.     factor = 0.5 * math.sin(time * speed) + 0.5
  16.     local finalPosition = initialPosition:Lerp(destinationPosition, factor)
  17.     script.Parent.CFrame = CFrame.new(finalPosition)
  18. end
  19. RunService.Stepped:Connect(movePlatform)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement