What are cframes used for in games besides teleportation?
Since CFrames store both position and rotation, they’re incredibly useful for anything involving 3D space. Whether you need to move, rotate, or align objects, CFrames are the answer.
For example, you can easily rotate a turret using CFrame.lookAt
, or handle calculations that involve angles and directions. Basically, whenever you’re working with 3D positioning or orientation, think of CFrames—they’re built for it.
They are used for camera cutscenes and Positioning/Orientation of objects.
for me CFrames are useful when needing to change the orientation and position of an object at the same time, it also has many useful properties and methods which are usefull
for example, multiplying a cframe by another will (idk how to explain it so here is a demo)
local part = workspace.Part
part.CFrame = part.CFrame * CFrame.new(0, 0, -10) -- move the part 10 studs in the part look/Z direction
-- Or
part.CFrame = part.CFrame * part.CFrame.LookVector * -10 -- does the same thing as the above example
the above script will make the gray move part 10 studs of where its facing and it will be in the same position of the red part
and many more methods that are useful for other stuff as well
chopping trees I guess. CFrame.LookVector/RightVector/UpVector are all very useful for many calculations.
One of the main use cases of CFrame is to manipulate a group of 3D objects through a single object, such as models or a bunch of parts welded together, which cannot be done using Vector3.
Taking character teleportation as an example, changing the HumanoidRootPart.Position
to a Vector3 value will only move that object, while changing the HumanoidRootPart.CFrame
to a CFrame value will move the entire character (the selected object + all other objects that are welded to it).
CFrame is an object that contains multiple values regarding position of object in 3D space.
You should prefer using CFrames over Vector3 as since it will be usually faster and would not override behavior of some instances like WeldConstraints for example.
out of curiousity when have you noticed assigning cframes to be faster? i often use them for camera/part positioning and for the latter i observed vectors being faster
That is likely because you always constructed vectors with raw numbers, while with cframes I bet you did a bunch of math operations.
And overall, I spoke about assigning and not constructing the class.
I would not recommend using vectors also because it overrides the behavior of most instances.
Animation using TweenService.
All animation uses CFrames but Animation editors take the knowledge of cframes out of it.
Creating custom rigs.
Welding.
Saving/loading builds on a baseplate or in a world.
Building in general.
Raycasting in general.
Skateboard mechanics. Hitbox mechanics.
Zone detection.
Character rotation.
I had a really long response, re-read the question and removed the long explanation. Let me know if you have a specific context you want to talk about.
raycasting doesnt use cframes in any of its params
GET OUT-
Bro chill. Ask yourself the question, how do you get the origin and direction? The answer is cframe.
If I had a gun in a game and wanted to raycast, I would like to find the cframe of where I want to do the raycast from. Range is a different parameter, but the RootPart.CFrame * GunSpecificObjectSpaceCFrame
would give me the origin and direction. Then multiply the direction by the range and then call the raycast function.
Almost all raycasts will need to index some sort of cframe and you will need the knowledge thereof.
Simply put, you do position and direction manipulation with cframe operations. Since raycasts are queries based around position and direction, it goes hand-in-hand.
I think he meant combining the raycastresult with cframes such as its magnitude and the position hit.
Im stating a fact in a joking manner dont take it so close to heart.
You can use .Unit method of Vector3 in some cases for raycast aswell
Why would you do that?Raycast result already returns the distance
So when you want to get the distance between two parts or something do you use subtraction along with the unit?
its more complicated than that.
If you want blant answer: (pos1-pos2).Magnitude
If you want more: i would recomend you googling raw equation of how does method .Magnitude works in roblox.
Unit is as far as i remember combination of magnitude with something and its purpose is to get direction; You likely had lesson about it in alghebra 7-9 grade.
here i think someone did a good enough explanation on how does magnitude works
Make sure to check out this aswell Vector3 | Documentation - Roblox Creator Hub