How to cap a character's velocity

I’m trying to cap a character’s velocity however I don’t know how to; I’m making a game with a custom movement system (PhysicsCharacterController) by @dthecoolest which has Sliding, Trimping, and Grappling (which I modified to include Bhopping and adjusted the values of attributes and trimping as such).

There’s this one glitch which I am stumped over on how to solve it, except for adding a velocity cap for the player.

You just press F and then right after Slash to open chat and somehow it registers that your still sliding and this makes you EXTREMELY fast if you just Slide and then Bhop.

I want to try and cap the velocity, so it doesn’t go over 125.

Any type of help is appreciated.

1 Like

couldn’t you just check if the player’s HumanoidRootPart’s AssemblyLinearVelocity.Magnitude is greater then a cetain number, it changes the velocity to that number by welding a part to the frount of the players chest and setting the AssemblyLinearVelocity to that parts LookVector times whatever?

something like

--- I think you already have a loop above this, but if you don't this should be in one
local MaxMagnitude = 4 --fool with this number
if rootPart.AssemblyLinearVelocity.Magnitude > MaxMagnitude then
    rootPart.AssemblyLinearVelocity = rootPart.PartThatsWeldedToThePlayersChest.CFrame.LookVector * MaxMagnitude
end
1 Like

Already done the first part, this could work but I want a more conventional method of doing it.

1 Like

What’s the code to register when the user stops sliding?

I haven’t tested this but maybe try inserting a LinearVelocity instance, and set the MaxForce to whatever you want. Having certain settings can make it so no velocity is given I believe.

function Slide:InputEnd()
	local data : PhysicsCharacterController = self.PhysicsCharacterController

	local model = data._Model
	if self._AutoRotateObject then
		self._AutoRotateObject.ShouldUpdate = true
	end

	model:SetAttribute("FlatFriction", model:GetAttribute("FlatFriction")) -- Reset friction back to normal
	local waist = model:FindFirstChild("Root", true)
	if waist then
		waist.C0 = self._C0_ORIGINAL
	end

	model:SetAttribute("WalkSpeed", self._OriginalWalkSpeed)
	model:SetAttribute("XZDragFactorVSquared", self._OriginalDragValue)

	self._SlideAnim:Stop(1)
end

This called with context action service or user input service?

It is called with ContextActionService. (Both InputBegan and InputEnd)

If this is the case, what would be the settings?

Ok so for Input End maybe try switching it to User Input Service as then you can detect if it was processed meaning it would run even when your talking or doing anything else

so idk if there is some kind of variable saying if you are sliding but you can do

game:GetService('UserInputService').InputEnded:Connect(function(input,processed)
	if processed == true and Sliding == false then
		return
	end
	
	if input.KeyCode == Enum.KeyCode.F then
		if Sliding == true then
			--Call input end
			Sliding = false
		end
	end
	
end)

Pretty sure this won’t work as you press F and then right after Slash (chat key) and I am not sure if it is going to be able to detect it fast enough.

Also, I don’t want to risk mobile support for my game.

This will detect any key press you do no matter if your doing anything else

I meant for the GameProcessed event.

You could just remove that bit then makes no difference

I have solved this by using LinearVelocity, setting its MaxForce to math.huge, making its Attachment0 to the RootAttachment in the RootPart, and just making it relative to the world and making the VectorVelocity 0,0,0 so the character can’t gain any momentum and it just cancels the slide basically. (This process happens when the character has >= 125 velocity which is deemed impossible to achieve unless somebody is using the glitch)

It gets destroyed when the game sees that the character has <= 60 velocity and has the LinearVelocity instance meaning their slide canceled out.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.