Jittering when changing character CFrame

Attempting to change a character’s humanoidrootpart cframe causing it to jitter, is this due to any relations to physics or? Is there any way to fix this? Like using AlignOrientation?

local function FaceMouse()
	local RootPos: Vector3, MousePosition : Vector3 = PlayerProperities.HRP.Position, Mouse.Hit.Position :: Vector3 | Vector3
	PlayerProperities.HRP.CFrame = CFrame.new(RootPos, MousePosition)
end

1 Like

The reason for the jitter is because CFrame.new(pos, lookAt) returns a CFrame whose position is at pos and whose orientation is directed towards lookAt. MousePosition.Y's value is probably 0 in this case, which causes the character model to sorta tilt downwards towards that. You’ll see that if you click directly in front of your character, it’ll cause it to fall over. You could create a new Vector3 that maintains the X and Z values of MousePosition while substituting MousePosition.Y with HRP.Position.Y to prevent the player from tilting on the Y axis:

local function FaceMouse()
	local RootPos: Vector3, MousePosition : Vector3 = PlayerProperities.HRP.Position, Mouse.Hit.Position :: Vector3 | Vector3
	PlayerProperities.HRP.CFrame = CFrame.new(RootPos, Vector3.new(MousePosition.X, PlayerProperities.HRP.Position.Y, MousePosition.Z))
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.