Hello, I'm NYDynamics and today I have attempted to script a Bezier curve Function. For some reason it returns in the output...
1 | 0 , 0 , 0 (x 3 ) |
2 | nil |
Even though they have positions it returns 0,0,0??? It would be great if someone could help! My code is...
01 | local P 0 = workspace.P 0 |
02 | local P 1 = workspace.P 1 |
03 | local P 2 = workspace.P 2 |
04 |
05 | local tan = (P 0. Position - P 2. Position).magnitude |
06 |
07 | function lerp(a,b,c) |
08 | return print (a + (b-a) * c) |
09 | end |
10 |
11 | function quadBezier(tan,P 0 ,P 1 ,P 2 ) |
12 | local L 1 = lerp(Vector 3. new(P 0 ),Vector 3. new(P 1 ),tan) |
13 | local L 2 = lerp(Vector 3. new(P 1 ),Vector 3. new(P 2 ),tan) |
14 |
15 | local quad = lerp(Vector 3. new(L 1 ),Vector 3. new(L 2 ),tan) |
16 | return print (quad) |
17 | end |
18 |
19 | quadBezier(tan,P 0 ,P 1 ,P 2 ) |
01 | local P 0 = workspace.P 0 |
02 | local P 1 = workspace.P 1 |
03 | local P 2 = workspace.P 2 |
04 |
05 | local tan = (P 0. Position - P 2. Position).magnitude |
06 |
07 | function lerp(a,b,c) |
08 | return a + (b-a) * c |
09 | end |
10 |
11 | function quadBezier(tan,P 0 ,P 1 ,P 2 ) |
12 | local L 1 = lerp(Vector 3. new(P 0 ),Vector 3. new(P 1 ),tan) |
13 | local L 2 = lerp(Vector 3. new(P 1 ),Vector 3. new(P 2 ),tan) |
14 |
15 | local quad = lerp(Vector 3. new(L 1 ),Vector 3. new(L 2 ),tan) |
16 | return quad |
17 | end |
18 |
19 | print (quadBezier(tan,P 0 ,P 1 ,P 2 )) |
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
^.