Character changes direction when moving backwards?

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)

3 Likes

Have you tried just setting the character’s HumanoidRootPart CFrame instead of using a bodygyro? Have you tried setting the priority to a different value to try to see if it maybe is getting set later on in the render process by a roblox script?

1 Like

I tried setting the CFrame but I didnt get the same result for the top down movement. I also did some research and some scripters were saying that body gyro was a better way to go.
but It does make sense that the body gyro could also be the problem

Late reply, I was looking for answers to a question of my own but I decided to help out.

The math is pretty simple, and it shouldn’t contain many problems. Could be something external interfering with it, is the Humanoid Property “AutoRotate” off?

1 Like

I have a similar problem, please help

Same with me also, I don’t know what is wrong with my top - down game. I tried body gyro like what you did and I got same results as you. When I did it with C Frame, result was same except I couldn’t see player facing different way.

vid - https://streamable.com/owufby

Actually I found the reason, setting humanoid.AutoRotate to false makes this not happen.

1 Like