Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Positions can be obtained by going into the properties of the parent part
- -- Position 1 - This is your initial position
- local position1 = Vector3.new(36,7.5,8)
- -- Position 2 - This is your goal position
- local position2 = Vector3.new(36,16,8)
- -- This variable modulates between 0 and 1
- local factor = 0
- -- These variables keep track of the part we're moving and the service we'll be getting for running our function
- local this = script.Parent
- local RunService = game:GetService("RunService")
- -- This function moves the platform
- function movePlatform (time, step)
- -- This is the code for calculating the factor. This is a sine function that modulates between 0 and 1.
- factor = 0.5 * math.sin(time) + 0.5
- -- This is a lerp function. Lerp interpolates between two positions by the factor given (0 is the initial, 1 is the goal).
- local finalPosition = position1:Lerp(position2, factor)
- -- This sets the part's position to our newly-created position
- this.CFrame = CFrame.new(finalPosition)
- end
- -- This connects our function to the RunService so that our function can run every frame.
- RunService.Stepped:Connect(movePlatform)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement