I’ve been looking for a way to just get one or two of the values from a vector 3 but cant find anything I know its probably simple but I don’t know what to do. help would be appreciated
local V3 = Vector3.new(12, 3, 20)
print(V3.X) -- 12
print(V3.Y) -- 3
print(V3.Z) -- 20
Don’t be ashamed of asking simple questions, understanding them are much more important then the complex ones.
ty this works but
how would I do this with CFrame rotation? since a Cframe has a vector 3 positions value and a vector 3 rotation value within the same CFrame value
One way to set a CFrame with both position and rotation it’d look like this:
local cf = CFrame.new(Position) * CFrame.Angles(math.rad(Xrot), math.rad(Yrot), math.rad(Zrot))
Position is a Vector3 value.
the Xrot, Yrot, and Zrot values would be the rotation of the CFrame.
we use math.rad(number) to convert a number from degrees to radians (which is what .Angles takes).
To get the Rotation Values from a CFrame you would do this.
Edit: there is a mistake in this code (see below post)
local cf = CFrame.new(Vector3.new(3, 5, 2)) * CFrame.Angles(math.rad(50), math.rad(15), math.rad(30))
local RotationOnly = cf - cf.Position
local Rotation = Vector3.new(math.deg(RotationOnly.X), math.deg(RotationOnly.Y), math.deg(RotationOnly.Z))
print(Rotation.X, Rotation.Y, Rotation.Z) -- 50, 15, 30
local cf = CFrame.new(Vector3.new(3, 5, 2)) * CFrame.Angles(math.rad(50), math.rad(15), math.rad(30))
local RotationOnly = cf - cf.Position
local Rotation = Vector3.new(math.deg(RotationOnly.X), math.deg(RotationOnly.Y), math.deg(RotationOnly.Z))
print(Rotation.X, Rotation.Y, Rotation.Z) -- 50, 15, 30
This code does work how you would expect…
It would actually print 0,0,0.
This is because in the second line you create a new cframe, which is essentially a clone of the first cframe, however without the positional aspect to it. Keep in mind its still a CFrame, so it still has a positional aspect to it, however its just all 0’s, hence why it prints 0,0,0.
There are many ways to get the value’s associated with how the CFrame is rotated, but the one i’d suggest to the OP is this…
local x,y,z = myCFrame:ToOrientation()