Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make the CFrame Angles not.. glitchy?

Asked by
zeptak 4
6 years ago

Hi, I've tried to make a "Surface Blast Doors", but my script everytimes make the doors open BUT not open. I use CFrame Lerp and it makes that like the doors are open and not moving, but for roblox it moves, it moves only like a 0.001 stud and I don't know how to fix it. Please help. There is my script.

01local db = false
02local open = false
03 
04script.Parent.ClickDetector.MouseClick:Connect(function()
05    warn("Checking if SBD's are open..")
06    if open == false then
07        warn("SBD's closed, checking if in move!")
08        if db == false then
09            warn("SBD's not moving. Opening SBD's!")
10            db = true
11            local finish = script.Parent.Parent.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
12            for i = 0,1,.00001 do
13                local cfm = script.Parent.Parent.PrimaryPart.CFrame:Lerp(finish,i)
14                script.Parent.Parent:SetPrimaryPartCFrame(cfm)
15                wait()
View all 41 lines...

(The doors itself are the ClickDetector, I made that just for testing.)

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

The problem is that you are not creating the CFrame from the start point.

Lerp is used to get the % between a start and end values (a CFrame is a list of value) in the value range 0~1 (1 being the end value). You are changing the start point each time resulting in a glichy effect.

Do not change the start or end points while doing the lerp.

1-- create a variable of the start point as it should not change
2local start = script.Parent.Parent.PrimaryPart.CFrame
3local finish = start * CFrame.Angles(0,-math.rad(90),0)
4 
5-- lerp from start to finish point
6for i = 0,1,.00001 do
7    cript.Parent.Parent:SetPrimaryPartCFrame(start:Lerp(finish, i))
8    wait()
9end

Hope this helps.

0
Thank you so much, you helped me a lot! zeptak 4 — 6y
Ad

Answer this question