I’m making a 2d platformer fighting game similar to smash, but one of the issues is that if you hold D or A and you let go before it turns all the way to one side, then you kinda see your character from the back and their moves aim outside of the arena.
local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
while true do
local Time = 0
while true do
if Humanoid.MoveDirection.Magnitude == 0 then RunService.RenderStepped:Wait() continue end
if Time > 1 then break end
local Pivot = Character:GetPivot()
local CF = CFrame.new(Pivot.Position, Pivot.Position + Humanoid.MoveDirection)
Character:PivotTo(Pivot:Lerp(CF, Time / 1))
Time += RunService.RenderStepped:Wait()
end
end
Copied and pasted that snippet from another thread. Here’s a snippet which I believe better fits what you’re asking for (you’ll need to disable the ‘W’ and ‘D’ keys).
local Game = game
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local function OnHumanoidMoveDirectionChanged()
local Position = Character:GetPivot().Position
local Direction = Humanoid.MoveDirection
if Direction ~= Vector3.new(-1, 0, 0) and Direction ~= Vector3.new(1, 0, 0) then return end
Character:PivotTo(CFrame.lookAt(Position, Position + Direction))
end
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(OnHumanoidMoveDirectionChanged)