Help with weird flinging

Hello there! i tried to recode my momentum script for my movement shooter, but for some reason, once i try to jump near a wall, i get flung around, instantly capping the momentum limit a lot of times


this is the momentum’s script code

local RunService = game:GetService("RunService")
local tweenService = game:GetService("TweenService")

-- Settings
local baseDecayPerSecond = 60
local stillDecayMultiplier = 5
local airtimeDecayDivider = 20
local moverForce = 1e6
local maxMomentum = 500

-- Variables
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local root :Part = char:WaitForChild("HumanoidRootPart")
local human = char:FindFirstChildOfClass("Humanoid")
local mover = Instance.new("LinearVelocity")
local storedMomentum = 0

-- Setup
mover.ForceLimitMode = Enum.ForceLimitMode.PerAxis
mover.MaxAxesForce = Vector3.new(moverForce, 0, moverForce)
mover.Attachment0 = root:FindFirstChildOfClass("Attachment")
mover.RelativeTo = Enum.ActuatorRelativeTo.World
mover.VelocityConstraintMode = Enum.VelocityConstraintMode.Vector
mover.Name = "Momentum mover"
mover.Parent = root

function lerp(v0, v1, t)
	return v0 + t * (v1 - v0);
end

-- Loop
RunService.RenderStepped:Connect(function(deltaTime: number) 
	local velocity = root.AssemblyLinearVelocity * Vector3.new(1,0,1)
	
	local direction = (human.MoveDirection * human.WalkSpeed + velocity * Vector3.new(1,0,1)).Unit
	if not direction or direction ~= direction then direction = Vector3.zero end
	local grounded = human.FloorMaterial ~= Enum.Material.Air
	
	local decay = baseDecayPerSecond
	if not grounded then decay /= airtimeDecayDivider end
	if human.MoveDirection == Vector3.zero then decay *= stillDecayMultiplier end
	
	if velocity.Magnitude >= storedMomentum then storedMomentum = velocity.Magnitude end
	storedMomentum = math.clamp(storedMomentum - decay * deltaTime, 0, maxMomentum)
	
	mover.VectorVelocity = direction * math.max(human.WalkSpeed * human.MoveDirection.Magnitude, storedMomentum)
end)

game:GetService("ContextActionService"):BindAction("particle test", function(_, state: Enum.UserInputState)
	if state ~= Enum.UserInputState.Begin then return end
	storedMomentum += 40
end, false, Enum.KeyCode.Z)

Have you tried lowering the force?

It also seems like the force is not going away fast, so it’s making the model move around all weird like that.

try lowering the force and making it go lower faster.

turns out 1e6 force was too much, based on my experiments it seems 1e4 is definiely the best choice for now, not too underpowered but not too strong
and yea the decay sure looks to be too low, causing that “drifting” effect, sadly its a bit hard to solve unless i crank the decay to extreme levels, and if i do that the momentum will be gone too fast, going from a movement shooter to just, shooter, but i increased it to 100 which seems to be good enough

1 Like