Hi!
I've recently been introduced to the function 'lerp' and it's showing usefulness regarding smooth CFrame movements. I found out a problem when using it though, the part goes into the centre of an 'end part' when I would like it to be touching the part at the end~.
My script is simple, there is a loop to lerp to the percentage of the i variable. It's just that I have no idea how to stop the lerp when it's touching the other part.
I've tried using lookvector but that hasn't solved my problem or I have done it wrong.
--[[
Variable creation
--]]
local this = script.Parent
local startCFrame = this.CorePart.CFrame -- the doors starting CFrame
local endCFrame = this.EndPart.CFrame-- where it should end up
--[[
Main code.
- For loop runs 0-100; lerp % of i
- wait(0.01) for smooth movement
--]]
for i = 0, 1, 0.1 do
this.CorePart.CFrame = startCFrame:lerp(endCFrame, i) -- I need this function to stop once touching the end part, not in the centre of the part.
wait(0.01)
end
Any help would be appreciated! Thank you! :)
QUICK LINKS The setup
~Animation to show problem
[EDIT] I also attempted to subtract half of the Y axis on the door but is somehow glitching. This is the script I used;
local this = script.Parent
local startCFrame = this.CorePart.CFrame
local endCFrame = this.EndPart.CFrame
local subtractCFrame = Vector3.new(0, -this.CorePart.CFrame.Y / 2, 0)
for i = 0, 1, 0.1 do
this.CorePart.CFrame = startCFrame:lerp(endCFrame - subtractCFrame, i)
wait(0.01)
end

1 comment
If you found a solution to your problem, you should answer your own question yourself.