Help With Roblox Mathematics?

I need help with Roblox math. I recently grabbed a module script from the tool box for a 3rd person camera, looked inside of it, and realized that I still had a lot to learn.

I have been searching and searching and searching for a helpful beginners tutorial on how all of this works, but I just haven’t found anything.

(This is just a bit of the code)

A link to a tutorial or even explaining how some of this code works would be VERY helpful.

1 Like

Let me explain it in parts aight?

First. I will try to explain CFrrames as its thhe CORE for movement of parts under anycase in roblox.

CFrame is used to define the position and orientation of a certain part. If you are FAMILIAR Matrix (which u might not be). You will be pleased to hear that CFrame is a matrix.
(sry if u dont know what matrix are.they are basically math objects (irl aswell btw)).

CFrame is called using

local CFrame = CFrame.new()

CFrame.new Accepts 2 Arguments.

Position and another position (will tell bout tht later).
First one is the cords for the part.it can be defined using x,y,z directly like this

CFrame.new(x,y,z)

--but i prefer this practice

CFrame.new(Vector3.new(x,y,z))

2nd one is used as a lookat. Basically imagine 2 parts. First parts front face is ur face. Now u want to look at the second part. So if CFrame existed irl you could do this

CFrame.new(YourHeadOrPart1,PartToLookAtOrPart2)

Though this only exists in roblox so no spinning heads 360 degree :sob:.

Now there are more terms but i will explain one last one.CFrame.Angles

The first one which i told u about is mostly used for positions while THIS is used for rotation.

But before i explain tht i wanna explain something else way more important.

A Vector3 uses degrees to define rotation.but CFrame uses radians.Radians are juat another unit for angles where 1 = 360 degrees. Now u could do some calculations to make degrees valid for cframe.but We have a library named maths and it has a function called math.rad to convert degrees to radians so no stress.back to angles

Lets say now u want to your face to face 90 Degrees to view a Beautiful Car. You could use the second parameter of the CFrame.new().but lets say god denied u access.(thts the best excuse i could come up with) so u are stuck with this. CFrame.Angles is similar to .new but it uses radians and those radians rotate the part or rotate it instead of setting its position.

YourHead.CFrame = CFrame.new(position) * CFrame.Angles(0,math.rad(90),0)

And ur face now faces 90 degrees suddenly. Wow.

Now i could explain CFrames more but i suggest you go to

Understanding CFrames.

Also follow the next arrticle aswell its for the math operations and then come back here or just search CFrame on dev wiki for more knowledge.

Hello guess u came back .

Script explanation

First line obtains the HRP (humanoidrootpart.its the part which is used to check/change position of player using vector3 ir cframes.)
In the next line it takes negative of total-pitch (it should be defined above),multiplies it with Camera-Offset (defined above. I will use D.AoD for things that should be defined either above of the provided script or and the down.).then it mutliplies the result of that by the cfrrame of hrp.

Not that the result is in Angles so that means they are offsetting the rotation.

Next stuff is also similar and if u read the articlees above u will understand it easily. Now thee next part involves raycasting. I have already explained it to someone so i will link that thread and another article which explains how raycasting works.

Now next part is just setting the cameras cframe to be the cframe calculate.

Next function updates character so it doesnt look weird and yeah thats all it. Was a long ride writing this. Hope this helps.

EDIT:
Sorry i didnt explain it good in the end.my fingers webt sore so took a break. Though i believe u might have understood it.

3 Likes

Thank you so much! I have been trying to figure this out for a while, and you helped a LOT. So thank you again.

That’s cap.

A lot of these you should/will learn in school, especially linear algebra, 2D physics, and trigonometry.
Don’t rush yourself, take your time to learn.

1 Like