As far as I understand, a CFrame can generally be broken down like this: CFrame.new(Vector3 pos, Vector3 lookAt) My last question was about using welding to allow for rotation, which I solved using constraints. I needed to allow rotation because I want a gun to point at the mouse (think Metroid Prime). Here's my code:
wait(2) playerTable = game.Players:GetChildren() player = playerTable[1] print(player) mouse = player:GetMouse() att = Instance.new("Attachment") att.Parent = player.Character["Right Arm"] con = script.Parent.GunCon con.Attachment1 = att con.Attachment0 = script.Parent.Attachment wait(10) while true do wait() script.Parent.CFrame = CFrame.new()--, mouse.Hit.p) end
If I set the position vector3 of the CFrame, it constantly messes with the position of the gun, as to be expected; however, I need to access the second argument of the CFrame without accessing the first. I want to leave the position be and use mouse.Hit.p as the orientation. I hope that makes sense. Thanks.
I think you could use BodyGyro to rotate the Parent of the script. That way you would only need to rotate BodyGyro's CFrame and since BodyGyro doesn't apply any force to keep its position, but does only to rotate it's parent, there should be no worry of CFrames position. Tutorial on body movers (BodyGyro at the end of the vid): https://www.youtube.com/watch?v=wlYBQBnDEVI .
Edit: Even better! You could combine this with the post above doing: BodyGyro.CFrame * CFrame.Angles()
I don't think you understand the full potential of CFrame. Passing a position and direction vector to CFrame is only one of several different CFrame constructors. No matter what constructor you use, your CFrame value will always have the same parameters: PositionX, PositionY, PositionZ, Rotation00, Rotation01, Rotation02, Rotation10, Rotation11, Rotation12, Rotation20, Rotation21, Rotation22
(in that order).
The first three arguments make up the 3D position for the CFrame, and last nine arguments comprise the rotation matrix. Now you see why there are different CFrame constructors, keeping track of each element in the rotation matrix every time you wanted to rotate something could get a bit complicated.
Position and rotation have no direct correlation with each other. You can change one without it effecting the other (just make sure the constructor allows for it). If you wanted to change the position without changing the rotation, here are a few examples...
-- Converting all vector dimensions to radians for the CFrame.Angles constructor local partRot = part.Rotation local rad = math.rad part.CFrame = CFrame.new(x, y, z) * CFrame.Angles(rad(partRot.X), rad(partRot.Y), rad(partRot.Z))
-- Gets the arguments after the 4th position, which is the rotation matrix. part.CFrame = CFrame.new(x, y, z, select(4, part.CFrame:components()))
If you wanted to change rotation without modifying position, here is an example...
-- Creating a new CFrame with a position with an empty rotation matrix, then filling it by using CFrame.Angles part.CFrame = CFrame.new(part.Position) * CFrame.Angles(x, y, z)
There are always several ways to do the same thing, some options are better than others depending on what you're doing. Anyways, hope this helped clear things up a bit. Let me know if you have any questions.