# How to CFrame an object towards a LookVector while maintaining current rotation

I am trying to rotate a part -15 degrees on the X axis based on a LookVector while maintaining the parts current orientation. I’ve been attempting this for a few hours using ToObjectSpace but I guess my knowledge of CFrame isn’t very admirable.

Here’s some images of what I’m trying to accomplish. The gray hinge part is the LookVector, the opaque blue part is the current rotation/position, and the semi-transparent blue part is where I want the part to end up (-15 degrees on the X axis).

Any thoughts on how I can achieve this?
Thanks

4 Likes

Do you mean rotate the part while keeping the same orientation? Orientation, position, and properties similar to them all are automatically updated whenever you update the CFrame in any way.
If you really want to keep the same orientation, then you could use CSG or a meshpart. I don’t see why you really need to preserve a constant orientation.

I’ve created something like what you were attempting to do.

``````local clone = workspace.Part:Clone()
clone.CFrame = workspace.Part.CFrame*CFrame.new(0,0,-2.5)*CFrame.Angles(-math.pi/12,0,0)
clone.Transparency = 0.5
clone.Parent = workspace
``````

(Size = 2,12,2)

``````Part.CFrame = Part.CFrame*CFrame.Angles(math.rad(15),0,0)
``````

Haven’t tested, but I’m pretty sure this is how you’d do that. Let me know if this works.

1 Like

This doesn’t solve my issue, I know how to rotate a part… I think I explained with the images what I am trying to accomplish. I’m essentially trying to do what you can do in studio, but instead of rotating on the axis of the world, rotating it on the axis of another part.

Instead of the axis being based on world space, it would be based on the space of another part, if that makes sense.

This rotates it 15 degrees using object space, I need it to rotate 15 degrees using ANOTHER objects space if that makes sense. Maybe I am not explaining it well.

You’re saying you want the translucent brick to rotate around the base of the opaque brick, but tilted away from the hinge brick by 15 degrees?

I want the opaque part to end up in the transparent parts position. -15 degrees on the X axis based on another parts CFrame. I am guessing I believe I will have to use ToObjectSpace and ToWorldSpace to accomplish this.

Figured it out, I don’t think this is the cleanest or most efficient way to do it but it works.

``````local PartCopy = Part:Clone()
local PartCF = Part.CFrame
local Character = workspace:WaitForChild("korky5000")
local RootPart = Character:FindFirstChild("HumanoidRootPart")
local HitDirection = (Part.CFrame.p-RootPart.Position).Unit