# How can I calculate the rotation for this?

Hello, I have a grab system and I have a problem. The problem is, I want the part being grabbed to face the player with the rotation it had before being grabbed. The code I tried works horizontally but not vertically. The vertical rotation only rotates in one direction.

``````local rx, ry, rz = (CFrame.lookAt(character.Head.Position, grabbedPart.Position)):ToOrientation()
grabbedPart.Orientation = grabbedPartBaseOrientation + Vector3.new(math.deg(rx),math.deg(ry),math.deg(rz)) - baseOrientation
``````

The rx, ry, rz is the rotation of the head facing the part being grabbed. The grabbedPartBaseOrientation is the orientation of the part being grabbed before it was grabbed. baseOrientation is rx, ry, rz but before it was grabbed.

2 Likes

Try just doing

``````(CFrame.lookAt(grabbedPart.Position, character.Head.Position) * savedRotation).Rotation
``````

Saved rotation should be the CFrame.Rotation of the part when it is picked up

3 Likes

That didnâ€™t work. Rotation doesnâ€™t exist for that.

1 Like

The part doesnâ€™t have a CFrame?

1 Like

It does (blahblahblah roblox text min max thing)

1 Like

Then make a variable called saved rotation and set it to the partâ€™s CFrame.Rotation

1 Like

Now this happens but itâ€™s very close!

1 Like

I did this but didnâ€™t do it correctly but I did it correctly but the problem above happens.

1 Like

Itâ€™s been a whole week why wonâ€™t anyone help?

1 Like

Do the same thing but remove the x rotation.

1 Like

what? can you explain more?
IGNORE IGNOre

1 Like

Do exactly what youâ€™re doing, but remove the x rotation of whatever CFrame youâ€™re setting the part to. Itâ€™s simple:

``````local _, y, z = part.CFrame:ToOrientation()

part.CFrame = CFrame.fromOrientation(0, y, z)
``````

or you could do:

``````part.CFrame = CFrame.fromOrientation(0, select(2, part.CFrame:ToOrientation()))
``````
1 Like

Removing X rotation makes the part not rotate

1 Like

Rotate the part and then do this line of code.

1 Like

This is the problem with the video above:

``````mousePosPart.CFrame = CFrame.new(mousePosPart.Position) * (CFrame.new(mousePosPart.Position, character.Head.Position) * CFrame.Angles(grabbedPartBaseRX,gpbrY,gpbrZ)).Rotation
``````

mousePosPart is the part being grabbed.
grabbedPartBaseRX,gpbrY,gpbrZ are the rotation of the part when first grabbed.

1 Like

Ok, like I said before, do this exact same code, but remove the x rotation using the code I provided earlier:

``````local cframe = CFrame.new(mousePosPart.Position) * (CFrame.new(mousePosPart.Position, character.Head.Position) * CFrame.Angles(grabbedPartBaseRX,gpbrY,gpbrZ)).Rotation

mousePosPart.CFrame = CFrame.fromOrientation(0, select(2, cframe:ToOrientation()))```
``````
1 Like

Now it does the same thing with the same problem but Vertical movement works now

1 Like

Can you send a video? I donâ€™t quite understand what you mean.

1 Like

Oh wait the vertical rotation broke.

1 Like

Do you want it to just follow the mouse, no rotation? Iâ€™m having trouble understanding.

1 Like