_Basic Vector3 Knowledge _Basic Math Skills
_Know and understand what a 1 to 360 degree turn is. _Understand the bare basic minimum of scripting <br/>
First of all let's establish what CFrame is.
CFrame/CoordinateFrame - The position and orientation(rotation) of an object.
So how is it set up?
How can i use it?
What are practical uses of CFrame?
CFrame is heavily used throughout roblox and is one of the most reliable tools to use.
CFrame is set up like this:
CFrame.new(0,0,0) --X, Y, and Zed values
Now for the professional devs that know CFrame we wont be getting into the all the other values of CFrame.
Now you can use this in countless ways. For example:
local part = instance.new("Part", game.workspace) part.Anchored = false part.BrickColor = BrickColor.new("Really red") part.Material = Enum.Material.Neon part.CFrame = CFrame.new(0, 1, 0) --setting the parts position one stud above 0, 0, 0
Yeah, ok but how do i rotate the part?
Simply do the following:
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(90), 0) --this would rotate the part 90 Degrees in the y direction --Also its best to use math.rad because lua doesn't operate the same way with degrees, but you can still treat it that way with math.radpart.
Now some people would use FromEularAngles or whatever but i choose not to based on preferance.
You can also use CFrame to position it accordingly to other parts.
local second_part = Instance.new('Part', game.workspace) --let's assume the properties of the part are the same excluding the CFrame. second_part.CFrame = CFrame.new(0, 3, 0) --three studs above 0,0,0 part.CFrame = second_part.CFrame + Vector3.new(0, 2, 0) --This would set our original part 2 studs above part2 --Now lets do that again but this time rotate the part by 90 degrees --How do we do that? by doing this part.CFrame = second_part.CFrame * CFrame.Angles(math.rad(90), 0, 0) + Vector3.new(0, 2, 0)
Now let's make our original part constantly spin:
while wait(.1) do part.CFrame = part.CFrame * CFrame.Angles(math.rad(1), 0, 0) end --this makes it spin 1 degree every tenth of a second
There is a ton more of Cframe information to cover but the wiki covers CFrame pretty well in my opinion.
But just in case you don't like the wiki here is my version of it.
Hope this short tutorial helped and as always,