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).
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.
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.
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.
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
local AngleCF = CFrame.new(Part.CFrame.p) * CFrame.Angles(math.rad(HitDirection.Z*15),0,math.rad(-HitDirection.X*15))
local AngledPartCF = PartCF:ToObjectSpace(AngleCF)
local AngledPartAngle = AngledPartCF - AngledPartCF.p
local EndCF = PartCF * AngledPartAngle * (PartCF-PartCF.p)
PartCopy.CFrame = EndCF
PartCopy.Parent = workspace
If anyone figures out a cleaner way to do this, let me know!