How to maintain player velocity when applying unique velocities

In this case I’m trying to tweak the physics engine a bit so all additional momentum gained from objects like conveyors or boosts is maintained horizontally until the player lands. I’ve never had to lay a finger on the physics engine for any of my game so I figure I’d drop by here.

Current (LocalScript, StarterPlayerScripts)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")

local function onStateChanged(oldState, newState)
	-- if changes state
	if oldState == Enum.HumanoidStateType.Freefall and newState == Enum.HumanoidStateType.Landed then
		-- read velocity
		local velocity = rootPart.Velocity
		
		-- maintain velocity
		while humanoid:GetState() == newState do
			rootPart.Velocity = Vector3.new(velocity.X, 0, velocity.Z)
			task.wait()
		end
	end
end

humanoid.StateChanged:Connect(onStateChanged)

And the current conveyor script I’m using to test this (yes, this is from a free model)

local Speed = script.Parent.Speed.Value

while true do 
	script.Parent.Velocity = script.Parent.CFrame.LookVector*Speed
	wait(0.1)
end

No clue where to start, frankly…

Current performance:
conveyor

js wanna say velocity is deprecated, use assembly linear velocity. I would try adding to the velocity instead of setting it rock solid. use += instead of =, that might work.

Helps with the speed a little but there’s still a noticeable drag when jumping from a conveyor.

1 Like