I am trying to learn how to do lerps since it's similar to doing Tweening
with and I need to make animations without the plugin so I need to do Lerp
and I read the wiki about it however, I don't understand the way the Roblox wiki explained it I tried some of their methods I don't get how to do it but, don't worry I still gave it a shot here is my 'shot'... This might get ugly(If it isn't already)
I NEED TO MAKE THE PART SMOOTHLY TRANSITION TO THE OTHER PART!
LERP PRACTICE
script.Parent.Touched:connect(function(part) print("Lerping") local humanoid = part.Parent:WaitForChild("Humanoid") if humanoid then script.Parent.CFrame:lerp(script.Parent.Parent.ApproachingPart.CFrame, .5) --[[ ApproachingPart is in the workspace and so is the Part this script is under. --]] end end)
Thank you for reading all the way I am sorry if this was ugly for you to watch.... But I need help and badly. So I hope you can help me out it would be greatly appreciated!
It looks like you want the brick to teleport halfway between its current CFrame and ApproachingPart's CFrame when a player touches it.
All that Start:Lerp(Destination, Percent)
does is return a CFrame
that is linearly interpolated between two points. Start
is the CFrame
you start with, Destination
is the CFrame you want to end with, and Percent
describes how much you want to tween in (e.g. setting Percent
to 0.50
will return a CFrame
that is halfway (50%) between Start and Destination. Setting Percent
to 1.00
will effectively return Destination (100%)).
In your script, all you forgot to do is make the CFrame of the part equal to the value to got from :Lerp
.
script.Parent.Touched:connect(function(part) print("Lerping") local humanoid = part.Parent:WaitForChild("Humanoid") if humanoid then script.Parent.CFrame = script.Parent.CFrame:lerp(script.Parent.Parent.ApproachingPart.CFrame, .5) -- set the parts CFrame to what you got from :Lerp() end end)
However, this is just one way of using :Lerp
. What :Lerp
is really useful for is making smooth transitions between two CFrames. To make the part smoothly transition between its current position and ApproachingPart's position, do this:
-- it is very good practice to store variables when you expect to use them frequently. -- it's also less clutter on the script. local startpart = script.Parent local approachingpart = game.Workspace.ApproachingPart -- the CFrame the part started with local startcf = startpart.CFrame -- the CFrame you want the part to end with local endcf = approachingpart.CFrame startpart.Touched:connect(function(part) local humanoid = part.Parent:WaitForChild("Humanoid") if humanoid then print("Lerping") -- this should probably be inside the if-statement for per = 0.00, 1.00, wait() do -- from 0% to 100% of the way, do... startpart.CFrame = startcf:lerp(endcf, per) wait() end end end)