So I'm making a plugin for gun developers like me to CFrame their character's arms and then printing out the CFrame they've produced. Pretty easy, right? Not when you think of some necessary features like local and global movement. The increments will be easy for me, not so much the local movement. I know how to make it move locally forward and backward. You do this:
Part.CFrame = Part.CFrame * (Part.CFrame.lookvector * 3) --This would make it go forward locally 3 studs Part.CFrame = Part.CFrame * (Part.CFrame.lookvector / 3) --This would make it go backward locally 3 studs
(If I'm wrong about that, then please, please correct me)
But how would I go moving the part up, down, left, or right locally? I simply can't think of anything...!
A CFrame is made out of 12 components: It's position in the Euclidean space and the rotation matrix which has 9 components.
[C00, C01, C02]
[C10, C11, C12]
[C20, C21, C22]
The rotation matrix can be viewed as normal vectors for the axes. (C00, C10, C20) is the normal on X, (C01, C11, C21) the normal on Y and (C02, C12, C22) the normal on Z
CFrame.lookVector is actually -(C02, C12, C22) thats why it moves on the Z axis (forward or backward) when you composite them
One way of moving the part in other directions it's to take the other 'lookVectors' for the desired axis.
So to move a part locally up
function lookVectorX(cf) local _, _, _, x, _, _, y, _, _, z = cf:components() return Vector3.new(x, y, z) end function lookVectorY(cf) local _, _, _, _, x, _, _, y, _, _, z = cf:components() return Vector3.new(x, y, z) end function lookVectorZ(cf) local _, _, _, _, _, x, _, _, y, _, _, z = cf:components() return Vector3.new(x, y, z) end p = script.Parent wait(4) p.CFrame = p.CFrame + (lookVectorY(p.CFrame) * 3)
And likewise with the other axis.