Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

2 comments

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

0

same problem in the lerp function

1 answer

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

1 comment

0

I still get 0,0,0

This discussion is preserved as it was. New answers, comments, and votes are closed.