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

Lerp never freaking works, code is erroring need breakdown?

Asked by 6 years ago

hey i don't understand how lerp works and if someone can please give an explanation of the concept of lerp, i can't set my character primarypart cFrame because the lookvector is counted as a vector

super stupid and or i'm just retarded

    for i = 1, 20, 0.5 do
        hrp.CFrame:lerp(hrp.Position + hrp.CFrame.lookVector * 8, i/11)
        wait(0.08)
    end
0
what is the error abnotaddable 920 — 6y

1 answer

Log in to vote
0
Answered by
Amiaa16 3227 Moderation Voter Community Moderator
6 years ago

Simpliest explaination of lerp: it returns a value between the first and the last value based on the percentage you specify.

Let's say your first value is Vector3.new(0,0,0) and your destination value is Vector3.new(100,0,0)

local firstVal = Vector3.new(0,0,0)
local destVal = Vector3.new(100,0,0)

Now, lerping those values by let's say 0.3 would return Vector3.new(30,0,0)

print(firstVal:lerp(destVal, 0.3)) --> 30, 0, 0
print(firstVal:lerp(destVal, 0.7)) --> 70, 0, 0

Get it? The 0.3 means it will return like 3/10 of the distance.

Now back to your code, it errors because CFrame:lerp()'s first argument has to be a CFrame aswell, while you're passing a Vector3.

But you can fix it by using CFrame.new()

for i = 1, 20, 0.5 do
    hrp.CFrame:lerp(CFrame.new(hrp.Position + hrp.CFrame.lookVector * 8), i/11)
    wait(0.08)
end
Ad

Answer this question