Snap player's orentation left or right

Hi there! I’m working on a 2d esq game and I want the player to instantly snap left and right when moving, unlike the smooth rotation as seen in the video.


I’ve tried to make it work by setting player’s cframes when they press A/D, but it just ends up causing issues and flinging the player or snapping back and forth uncontrollably. I’ve also looked for similar topics but nothing’s worked yet. If a solution already exists please point me there.

This seemed to work fine for me

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local hum:Humanoid = char.Humanoid
hum.AutoRotate = false

local function setCharRotation(rotation)
	local angles = CFrame.Angles(0,math.rad(rotation),0)
	char:PivotTo(CFrame.new(char:GetPivot().Position) * angles)
end

game.UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.A then
		setCharRotation(180)
	elseif input.KeyCode == Enum.KeyCode.D then
		setCharRotation(0)
	end
end)

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