Trouble with CFrame.new(pos) * CFrame.Angles(x, y, 0) affecting position on the X

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Making a NPC rotate purely in it’s center no movement.

  2. What is the issue? Include screenshots / videos if possible!
    Rotating on the Y axis works fine, when rotating on the X it begins to move forward and backward weirdly.
    Rotation should not be affecting his position at all?

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using euler angles, rotation order etc, even subtracting prevx and prevy and such.

Here’s my current code, I just want to emphasize that the rotation should just be affecting his rotation, not his position but for some reason it affects his position??

function wobbleEffect()
	local startCF = SCP.PrimaryPart.CFrame
	local start = tick()
	local prevY = 0
	local prevX = 0
	
	runService.Heartbeat:Connect(function(deltaTime)
		local time = tick() --tick() - start
		local sineY = math.sin(time * 2) * 2.5
		local sineX = math.sin(time * .5) * 1.5
		
		startCF = CFrame.new(humanoidRootPart.Position) * startCF.Rotation
		SCP:PivotTo(startCF * CFrame.Angles(math.rad(sineX), math.rad(sineY), 0))
	end)
end

Yes I can see that I added startCF = cframe.new hum position, but in the first place the rotation should not even be affecting the position, is there any workaround while still allowing said NPC to be moved by physics?

this is due to the way you’re updating the startCF variable. When you use CFrame.new(humanoidRootPart.Position) * startCF.Rotation, it resets the position to the humanoidRootPart’s position every frame.
fix it by separating the rotation from the position.

function wobbleEffect()
	local startCF = SCP.PrimaryPart.CFrame
	local start = tick()
	
	runService.Heartbeat:Connect(function(deltaTime)
		local time = tick() --tick() - start
		local sineY = math.sin(time * 2) * 2.5
		local sineX = math.sin(time * .5) * 1.5
		
		local position = startCF.Position
		local rotation = startCF.Rotation * CFrame.Angles(math.rad(sineX), math.rad(sineY), 0)
		
		SCP:PivotTo(CFrame.new(position) * rotation)
	end)
end

1 Like

Oh my god I am forever grateful, cheers!

1 Like

Is there a way to make rotation not affect his position? like I generally don’t understand why this happens.
I updated the title to better describe the issue

Or any other CFrame wizards out there can explain to me why rotation affects his position when I don’t want it to and how I can stop it?

i already explained to you though

No why does rotation affect his position if I want to set his position to his current position and not a pre-stored one?