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)