Character movement glitching in game

Hey there.

While play testing my game, I stumbled upon a movement issue with the character as a result of the identified script below. No idea on how to fix it as I’ve been trying and looking for solutions for quite some time.

In the video below, you can see in the beginning the movement is slow to start with, but then resumes to normal walkspeed. Afterwards, you can see that I stop and press the “S” key to go backwards. Immediately, my character speeds up and moves to the right and occasionally corrects itself to going straight.

Here is the script:

local cam = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer

game:GetService("RunService").RenderStepped:Connect(function()
	if plr.Character then
		local rootPart = plr.Character:WaitForChild("HumanoidRootPart")
		if rootPart then
			rootPart.CFrame = CFrame.new(rootPart.CFrame.p, rootPart.CFrame.p + Vector3.new(cam.CFrame.LookVector.X,0,cam.CFrame.LookVector.Z))
		end
	end
end)
3 Likes

Is it possible that the gun is colliding with the terrain causing you to slow down? Make sure it is CanCollide = false.

Or if the weapon is too big you can set the parts to massless.

1 Like

I’ve had this problem before with weapons I’ve made for fighting games. The best thing you can do to combat this is to make all the parts in your weapon model very small (size of 0.2, 0.2, 0.2 is good, but do 0.05, 0.05, 0.05 for good measure), but then you can scale these parts up back to size with SpecialMeshes using the Scale property. This should remove any weird flinging and movement while your weapon is out.

Make sure massless is true on all your weapons.

1 Like

The player is moving relative to the direction the camera is facing… Since you’re camera is on an angle, you’re player is moving to the left a little when u move forward and moving to the right a little when you move backwards. You should find the LookVector of the camera without the angle you manually set, so u can subtract the angle of the camera that you manually set by the actual angle of the camera.

1 Like

I’ve already done some testing with the guns and the guns are not the problem. I’ve already had CanCollide = false. In addition to that, I did what you said to do regarding the massless setting as well, and the glitch still happens. When I remove the RotateChar localscript, the movement works normally.

1 Like

After looking at the Wiki, I found that ROBLOX has a setting that makes the character face the direction the camera is facing.

All I did was replace the code that I already had in the script with

local Settings = UserSettings()
local GameSettings = Settings.GameSettings
GameSettings.RotationType = Enum.RotationType.CameraRelative

Works like a charm and the movement is fixed!

3 Likes