local directions = getDirectionsToProcess()
local targetPosition = part.Position
for _, direction in ipairs(directions) do
local offset = (targetVelocity * step) * direction
targetPosition = targetPosition + offset
end
part.Position = targetPosition
I’m trying to move a part using WASD keys, it works fine but I had one problem.
I want to rotate my part on the same direction as the player’s camera, exactly the orientation property. I tried to transform it to euleranglesXYZ by doing local x,y,z = CFrame.new():ToEulerAnglesXYZ() ; print(y) but it gave me another number.
Orientation is derived from the CFrame, it isn’t a real property itself, so changing it directly is unlikely to do what you want. If you want to rotate a part relative to the camera, you can use the camera axes to create a rotation CFrame and multiply the part’s CFrame by that.
I’m not exactly sure what the code you provided does, but if you’re looking to get the camera’s Y orientation in world space you can use CFrame:ToEulerAnglesYXZ(). As the documentation says: “Returns approximate angles that could be used to generate the CFrame, if angles were applied in Z, X, Y order.” So, you can just get the Y angle and use that to rotate your part.
local Camera = workspace.CurrentCamera
local _, Y, _ = Camera.CFrame:ToEulerAnglesYXZ()
Part.Orientation = Vector3.new(0, math.deg(Y), 0) -- Angles are in radians and .Orientation uses degress so converting from radians to degrees