Linear Velocity pushes player down into ground

I’m trying to make a custom movement system for an FPS game I’m working on with my friends. When I hold W down and the player moves forward they’re being pushed down into the ground for some reason.
Here’s a video of that:

Here’s my code:
(MaxSpeed is 25)

local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local Humanoid = character:WaitForChild("Humanoid")
local maxSpeed = Humanoid:GetAttribute("MaxSpeed")

local wPressed = false
local currentSpeed = 0
local velocityMultiplier = 20

local velocity = Instance.new("LinearVelocity")
velocity.MaxForce = math.huge
velocity.RelativeTo = Enum.ActuatorRelativeTo.World
velocity.Attachment0 = character.HumanoidRootPart.RootAttachment
velocity.Parent = character.HumanoidRootPart

UserInputService.InputBegan:Connect(function(input, chat)
	if chat then return end
	if input.KeyCode == Enum.KeyCode.W then
		wPressed = true
	end
end)

UserInputService.InputEnded:Connect(function(input, chat)
	if chat then return end
	if input.KeyCode == Enum.KeyCode.W then
		wPressed = false
	end
end)

RunService.Stepped:Connect(function(tm, deltaTime)
	if wPressed then
		if velocity.VectorVelocity.Magnitude < maxSpeed then
			velocity.VectorVelocity += character.HumanoidRootPart.CFrame.LookVector * velocityMultiplier * deltaTime
		end
	else
		if velocity.VectorVelocity.Magnitude > 1 then
			velocity.VectorVelocity -= character.HumanoidRootPart.CFrame.LookVector * velocityMultiplier * deltaTime
		elseif velocity.VectorVelocity.Magnitude < 1 then
			velocity.VectorVelocity = Vector3.new(0, 0, 0)
		end
	end
end)

Any way to solve this? Thanks in advance :slight_smile:

1 Like

The lookvector has the possibility of looking down or up due to animations or physics creating up or down movement.

To remove this get rid of the y axis by multiplying it by zero.

*Vector3.new(1,0,1)

I applied the change and tested, but now the character just floats forward whenever they step off a platform (spawnpoint). And when I rotate the character while pressing W it just keeps moving the player into the ground and speeds up for some reason.

1 Like

Hello, I am encountering the exact same issue and have been searching the entire day for a solution…
please help, did anyone find a solution for this?

Sorry to necropost but was this ever solved?

Nope never, I just switched to using AssemblyLinearVelocity instead. dunno whats the point of linear velocity.

Have u ever tried the VelocityConstraintMode.Line ?

That would have been a good idea but I felt like instancing more attachments and stuff like that was too messy so I just edit the assembly velocity.