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 6 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...

10,0,0(x3)
2nil

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

01local P0 = workspace.P0
02local P1 = workspace.P1
03local P2 = workspace.P2
04 
05local tan = (P0.Position - P2.Position).magnitude
06 
07function lerp(a,b,c)
08    return print(a + (b-a) * c)
09end
10 
11function quadBezier(tan,P0,P1,P2)
12    local L1 = lerp(Vector3.new(P0),Vector3.new(P1),tan)
13    local L2 = lerp(Vector3.new(P1),Vector3.new(P2),tan)
14 
15    local quad = lerp(Vector3.new(L1),Vector3.new(L2),tan)
16    return print(quad)
17end
18 
19quadBezier(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 — 6y
0
same problem in the lerp function thebayou 441 — 6y

1 answer

Log in to vote
0
Answered by
thebayou 441 Moderation Voter
6 years ago
01local P0 = workspace.P0
02local P1 = workspace.P1
03local P2 = workspace.P2
04 
05local tan = (P0.Position - P2.Position).magnitude
06 
07function lerp(a,b,c)
08    return a + (b-a) * c
09end
10 
11function quadBezier(tan,P0,P1,P2)
12    local L1 = lerp(Vector3.new(P0),Vector3.new(P1),tan)
13    local L2 = lerp(Vector3.new(P1),Vector3.new(P2),tan)
14 
15    local quad = lerp(Vector3.new(L1),Vector3.new(L2),tan)
16    return quad
17end
18 
19print(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 — 6y
Ad

Answer this question