How can I apply math into my code?

I’m not the strongest at math and I kinda want to get better. I want to use math in a more practical way instead of just memorizing formulas. how can I use math in my code. Right now I’m learning about vertical/ Horizontal asymptotes and I’m wondering if I can use this function to animate cframes

image

I have tried doing this but idk what I’m really doing

local x = 10 
local y = 1/x

part.CFrame = part.CFrame * CFrame.new(0, 1/x, 0, y)

1 Like

Do you mean like:

local y = function(x)
	return 1 / x
end

for x = 0.1, 10, 0.1 do
	part.CFrame = CFrame.new(x, y(x), 0)
	wait()
end

?

1 Like

Im only in geometry this year but i think i know what is happening.

so with the graph there are two values that are constantly changing (the y and x). With the code you have right now it is just finding the one point on the line and placing the part in one area (you probably already knew that stuff)

To animate the part’s CFrame you can use TweenService. Im not exactly sure if you are able to make your own EasingStyles but this page may help :slight_smile:

Good luck :smiley:

Edit: If you are going to make your own tweening code (Not using Roblox’s api) make sure to stray away from using wait() and use something like RunService.RenderStepped:Wait()

2 Likes

I haven’t seen this function before I’m wondering if these two are the same

local y = function(x)
	return 1/x
end

local function test(x)
	return 1/x
	
end

local y = test(x)

They’re just different ways of defining a function, since functions are technically variables in Lua.

1 Like

so they are formatted differently but do the same thing?

Yes, either way you are defining a variable. Using the function keyword specifies that it is being defined as a function.