How can I fix this weird rotation problem?

To improve my skills I was working on a small project similar to “Keep Talking and Nobody Explodes”. I got the explosive rotating, however it won’t always rotate the same up and down.

Notice how it tilts differently from a different angle, even though I moved my mouse the same way each time.

My code for changing the explosive’s cframe is fairly short:

local change = (mousePos - lastMousePos)/5
			
local currentCFrame = currentExplosive:GetPrimaryPartCFrame()
local angles = CFrame.Angles( -math.rad(change.Y), math.rad(change.X), 0 )	
setCF(currentCFrame * angles)

Please note that it has nothing to do with “setCF”! setCF is just a shorter version of “model:SetPrimaryPartCFrame()”.


Any ideas on why this happens? I have a good feeling that its some simple cframe math to fix it.

1 Like

When using that CFrame multiplication formula.

The axis of rotation is dependent on the parts current CFrame.

To make it relative to world axis which doesn’t change change the order it is being multiplied by, example is in my CFrame tutorial.

1 Like

I’m still kind of confused… what would I have to change about my current multiplication to achieve this result? Do I multiple angles by currentCFrame and then add that result’s rotation to the explosive’s position?

This actually worked!
For anybody with a similar issue:

local currentCFrame = currentExplosive:GetPrimaryPartCFrame()
local angles = CFrame.Angles( -math.rad(change.Y), math.rad(change.X), 0 ) * currentCFrame

setCF(angles.Rotation + currentExplosive.PrimaryPart.Position)