Changing the orientation of an Object in a CFrame with a script

Hello, is there a way to change the Orientation of an object in a CFrame.

2 Likes
part.CFrame = CFrame.Angles(math.rad(50),0,math.rad(20))
4 Likes

Yes, you can change the orientation of an object in a CFrame by using the lookVector, upVector, and rightVector properties of the CFrame.

Here’s an example:

-- Get the current CFrame of the part
local part = game.Workspace.Part
local cf = part.CFrame

-- Define a new lookVector and upVector for the part
local newLookVector = Vector3.new(0, 0, -1)
local newUpVector = Vector3.new(0, 1, 0)

-- Set the orientation of the CFrame using the new vectors
cf = CFrame.new(cf.Position, cf.Position + newLookVector, newUpVector)

-- Set the new CFrame for the part
part.CFrame = cf

In this example, we first get the current CFrame of a part in the game world. Then, we define new lookVector and upVector vectors for the part. Finally, we set the orientation of the CFrame using the CFrame.new constructor with the part’s current position and the new lookVector and upVector vectors. Finally, we set the new CFrame for the part.

You can adjust the newLookVector and newUpVector vectors to achieve the desired orientation for your object.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.