Character is pushed forwards whilst strafing

So I’m having an odd issue concerning the players movement.
Whenever the player strafes perpendicular to their facing direction, they are slowly moved forwards.

The problem only exists under the two conditions:

  • The model type is R6
  • There are walking and running animations

So the question is why does the walk/run animation cause this, and how can I fix it. I have messed with it for a bit and am wondering if anyone else has any solutions.

If you wish to replicate this issue; Put the following code in a local script in either StarterCharacterScripts or StarterPlayerScripts and have the model types be set to R6.

local runService = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")

local Aimlocked = false
local function AimlockHotkey(ActionName,State)
	if State == Enum.UserInputState.Begin then
		Aimlocked = not Aimlocked
	end
end

local function Aimlock()
	local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	local humanoid:Humanoid = Character:FindFirstChild("Humanoid")
	if not Aimlocked then
		humanoid.AutoRotate = true
		return	
	end
	local Mouse = game.Players.LocalPlayer:GetMouse()
	local CharacterPart = Character.PrimaryPart
	humanoid.AutoRotate = false
	CharacterPart.CFrame = CFrame.new(CharacterPart.Position, Vector3.new(Mouse.Hit.X, CharacterPart.Position.Y, Mouse.Hit.Z))
end
CAS:BindAction("AimlockToggle",AimlockHotkey,false,Enum.KeyCode.LeftShift)
runService:BindToRenderStep("character",Enum.RenderPriority.Character.Value,Aimlock)

(If you do not disable shiftlock or have it enabled in game settings you might want to change the keycode for the Context Action Service at the bottom)

i believe its fixed if you convert it to use alignoriention rather than natively change the cframe of the char

local runService = game:GetService("RunService")
local CAS = game:GetService("ContextActionService")

local Aimlocked = false
local AlignOrientation = nil

local function AimlockHotkey(ActionName, State)
	if State == Enum.UserInputState.Begin then
		Aimlocked = not Aimlocked

		local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
		local humanoid:Humanoid = Character:FindFirstChild("Humanoid")
		local CharacterPart = Character.PrimaryPart

		if Aimlocked then
			if not AlignOrientation then
				AlignOrientation = Instance.new("AlignOrientation")
				AlignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
				AlignOrientation.RigidityEnabled = true
				AlignOrientation.Attachment0 = CharacterPart:FindFirstChild("RootAttachment") or Instance.new("Attachment", CharacterPart)
				AlignOrientation.Parent = CharacterPart
			end
			humanoid.AutoRotate = false
		else
			if AlignOrientation then
				AlignOrientation:Destroy()
				AlignOrientation = nil
			end
			humanoid.AutoRotate = true
		end
	end
end

local function Aimlock()
	if not Aimlocked then
		return
	end
	local Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
	local Mouse = game.Players.LocalPlayer:GetMouse()
	local CharacterPart = Character.PrimaryPart
	local targetPos = Vector3.new(Mouse.Hit.X, CharacterPart.Position.Y, Mouse.Hit.Z)
	local lookAt = CFrame.lookAt(CharacterPart.Position, targetPos)

	if AlignOrientation then
		AlignOrientation.CFrame = lookAt
	end
end

CAS:BindAction("AimlockToggle", AimlockHotkey, false, Enum.KeyCode.LeftShift)
runService:BindToRenderStep("character", Enum.RenderPriority.Character.Value, Aimlock)

Thanks, this works perfectly.

Though I am still somewhat confused as to what engine jank caused the issue before.

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