Help with the sliding system

Working on a custom movement system that has sliding, but I can’t get the “After Slide” velocity to be working properly.

When the player cancels theyre slide at the same direction they are walking it adds both velocities resulting in the “After slide” being faster than the player instead of conserving the momentum. How do I normalize velocities so that it acts like its conserving momentum and doesn’t add it?


(AfterSliding the player speeds up which isn’t suppose to happen)

I also want to keep this part of the afterslide velocity as it feels pretty good and slippery

I’ve tried multiple solutions though its so hard to explain but most of them eliminates the velocity making it linear and terrible when moving to other directions

MainCode:

RunService.Heartbeat:Connect(function()
	--Get the humanoid CF
	local HumanoidCurrentCFrame = IfDirectionLock() 
	ControllerManager.FacingDirection = HumanoidCurrentCFrame.LookVector
	
	local HumanoidForward = HumanoidCurrentCFrame.LookVector
	local HumanoidRight = HumanoidCurrentCFrame.RightVector

	--Gets the direction of the forward and right vectors, based on input
	local WalkDirection = WalkInput()
	local StrafeDirection = StrafeInput()
	local FallAccel= FallAccelHandler()
	CurrentWalkDir = WalkDirection
	CurrentStrafeDir = StrafeDirection

	--Calculates the Speed of the forward velocity
	local WalkMove = MoveHandler.Movement(WalkDirection, CurrentWalkMove, WalkTarget, WalkStep)
	local WalkFall = MoveHandler.FallMovement(WalkDirection, CurrentWalkFall, 15, FallAccel)
	local WalkJump = MoveHandler.Movement(WalkDirection, CurrentWalkJump, 0, 0.7)
	CurrentWalkMove = WalkMove
	CurrentWalkFall = WalkFall
	CurrentWalkJump = WalkJump

	--Calculates the Speed of the right velocity
	local StrafeMove = MoveHandler.Movement(StrafeDirection, CurrentStrafeMove, StrafeTarget, StrafeStep)
	local StrafeFall = MoveHandler.FallMovement(StrafeDirection, CurrentStrafeFall, 15, FallAccel)
	local StrafeJump = MoveHandler.Movement(StrafeDirection,CurrentStrafeJump, 0, 0.7)
	CurrentStrafeMove = StrafeMove
	CurrentStrafeFall = StrafeFall
	CurrentStrafeJump = StrafeJump

	--Adds the multipliers
	TotalWalkSpeed = WalkMove + WalkFall + WalkJump
	TotalStrafeSpeed = StrafeMove + StrafeFall + StrafeJump

	--Applies the multipliers to the direction
	local HumanoidVector2Forward = Vector2.new(HumanoidForward.X, HumanoidForward.Z)
	local HumanoidVector2Right = Vector2.new(HumanoidRight.X, HumanoidRight.Z)
	local WalkVeloc = HumanoidVector2Forward * (TotalWalkSpeed)
	local StrafeVeloc = HumanoidVector2Right * (TotalStrafeSpeed)
	
	--Adds the vector2 velocities, IsSlidingMod is set to 0 when sliding
	local PreVeloc = MoveHandler.NormalizeVector(WalkVeloc + StrafeVeloc, TotalWalkSpeed, TotalStrafeSpeed) * IsSlidingMod
	local PreSldingVeloc = SlideHandler.SlideVeloc()
	
	--Checks the walls then applies velocity
	local TotalCalculatedVeloc = PreVeloc + PreSldingVeloc
	local VelocFinal = WallChecker.CheckWall(TotalCalculatedVeloc)
	PlayerVelocity.PlaneVelocity = Vector2.new(VelocFinal.X, VelocFinal.Y)
end)

Sliding Code

function module.SlideVeloc()
	--Gets The Cframe of the char before the slide
	local ForwardCF = HumanoidCFrameLock.LookVector
	local RightCF = HumanoidCFrameLock.RightVector
	
	--Calculates the multipliers and records it
	local WalkVeloc = MovementHandler.Movement(SlideWalkDir, CurrentWalkVeloc, 0, Step)
	local StrafeVeloc = MovementHandler.Movement(SlideStrafeDir, CurrentStrafeVeloc, 0, Step)
	CurrentWalkVeloc = WalkVeloc
	CurrentStrafeVeloc = StrafeVeloc
	
	--Calculates the velocity with the multipliers
	local SlideWalk = Vector2.new(ForwardCF.X, ForwardCF.Z) * WalkVeloc
	local SlideStrafe = Vector2.new(RightCF.X, RightCF.Z) * StrafeVeloc

	--Adds all the velocity and returns it to the main script to be added with the main velocity
	local FinalVector = SlideWalk + SlideStrafe
	
	return FinalVector
end
1 Like