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

Bezier Curves I dont know why I am getting no error but it returns wierdly?

Asked by 5 years ago

Hello, I'm NYDynamics and today I have attempted to script a Bezier curve Function. For some reason it returns in the output...

0,0,0(x3)
nil

Even though they have positions it returns 0,0,0??? It would be great if someone could help! My code is...

local P0 = workspace.P0
local P1 = workspace.P1
local P2 = workspace.P2

local tan = (P0.Position - P2.Position).magnitude

function lerp(a,b,c)
    return print(a + (b-a) * c)
end

function quadBezier(tan,P0,P1,P2)
    local L1 = lerp(Vector3.new(P0),Vector3.new(P1),tan)
    local L2 = lerp(Vector3.new(P1),Vector3.new(P2),tan)

    local quad = lerp(Vector3.new(L1),Vector3.new(L2),tan)
    return print(quad)
end

quadBezier(tan,P0,P1,P2)
0
First of all print returns nil, and in quadBezier you write "return print(quad)" instead of just "return quad" which means it will return nil thebayou 441 — 5y
0
same problem in the lerp function thebayou 441 — 5y

1 answer

Log in to vote
0
Answered by
thebayou 441 Moderation Voter
5 years ago
local P0 = workspace.P0
local P1 = workspace.P1
local P2 = workspace.P2

local tan = (P0.Position - P2.Position).magnitude

function lerp(a,b,c)
    return a + (b-a) * c
end

function quadBezier(tan,P0,P1,P2)
    local L1 = lerp(Vector3.new(P0),Vector3.new(P1),tan)
    local L2 = lerp(Vector3.new(P1),Vector3.new(P2),tan)

    local quad = lerp(Vector3.new(L1),Vector3.new(L2),tan)
    return quad
end

print(quadBezier(tan,P0,P1,P2))

The problem is that you're telling the program to return print(...), which will return the value the print function returns, which is nil. What you want is just return whatever ^.

0
I still get `0,0,0` NYDynamics 71 — 5y
Ad

Answer this question