Hi, I just encountered an issue with my Top-down shooter game where whenever I start walking backwards with my character it changes direction completely from the initial direction it was facing. if what I wrote was confusing check out the video below.
As you can see when the player starts walking backwards my character starts facing another direction.
Here is the script I have for my “Player face mouse script”
The Code
local player = game.Players.LocalPlayer
local gyro = nil
local mouse = player:GetMouse()
mouse.TargetFilter = game.Workspace.Maps
local runService = game:GetService(‘RunService’)
local function onCharacterAdded(character)
local torso = game.Players.LocalPlayer.Character:WaitForChild(“HumanoidRootPart”)
gyro = Instance.new(‘BodyGyro’, torso)
gyro.P = 50000
gyro.MaxTorque = Vector3.new(0, 10000, 0)
local humanoid = character:WaitForChild(‘Humanoid’)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
end
local function isnan(x) return x ~= x end
local function onRenderStep()
if gyro then
local mouseHit = mouse.Hit.p
if not (isnan(mouseHit.X) or isnan(mouseHit.Y) or isnan(mouseHit.Z)) then
gyro.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position, mouseHit)
end
end
end
while not player.Character do wait() end
onCharacterAdded(player.Character)
player.CharacterAdded:connect(onCharacterAdded)
runService:BindToRenderStep(‘TrackMouse’, Enum.RenderPriority.Input.Value, onRenderStep)