Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Roblox Studio Moving Platform Script

a guest Apr 9th, 2020 260 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Positions can be obtained by going into the properties of the parent part
  2. -- Position 1 - This is your initial position
  3. local position1 = Vector3.new(36,7.5,8)
  4. -- Position 2 - This is your goal position
  5. local position2 = Vector3.new(36,16,8)
  6.  
  7. -- This variable modulates between 0 and 1
  8. local factor = 0
  9.  
  10. -- These variables keep track of the part we're moving and the service we'll be getting for running our function
  11. local this = script.Parent
  12. local RunService = game:GetService("RunService")
  13.  
  14. -- This function moves the platform
  15. function movePlatform (time, step)
  16.     -- This is the code for calculating the factor. This is a sine function that modulates between 0 and 1.
  17.     factor = 0.5 * math.sin(time) + 0.5
  18.    
  19.     -- This is a lerp function. Lerp interpolates between two positions by the factor given (0 is the initial, 1 is the goal).
  20.     local finalPosition = position1:Lerp(position2, factor)
  21.    
  22.     -- This sets the part's position to our newly-created position
  23.     this.CFrame = CFrame.new(finalPosition)
  24. end
  25.  
  26. -- This connects our function to the RunService so that our function can run every frame.
  27. RunService.Stepped:Connect(movePlatform)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top