Help With Sliding Mechanic In My Game

So I’m trying to make a game with a lot of movement mechanics and I want one of them to be a sliding mechanic where if a player presses and holds a button they will continue to be pushed in the direction they were first facing when they pressed it even if they turn to face the other way. I’m aiming for something like the slide mechanic from ULTRAKILL. I tried BodyForces, but those keep the player from moving downward if they slide off of a ledge, and Tweening is way too janky. I tried to use VectorForces, which I imagine could work but I don’t know how to get it to where the player isn’t dragged slowly across the floor instead of actually sliding. If anyone could help it would be greatly appreciated.

1 Like

I believe you are using LinearVelocity which is you can get around it by using plane mode.

For BodyVelocity you have to set max force on Y to zero

Unfortunately for both methods this doesn’t really simulate physics which has acceleration since it has to have a high force and override the default humanoid drag forces. Consequently, making a custom character controller is recommended which I will try to release as an example later on.

--Linear velocity with no forces on y Axis
local char = script.Parent --Indicates input into local script as starter character scripts
local RunService = game:GetService("RunService")

local humanoid : Humanoid = char:WaitForChild("Humanoid")
local rootPart = humanoid.RootPart
local UserInputService = game:GetService("UserInputService")

local attachment = Instance.new("Attachment")
attachment.Parent = rootPart
attachment.Name = "VectorForceAttachment"
attachment.WorldPosition = rootPart.AssemblyCenterOfMass


local vel = Instance.new("LinearVelocity")
vel.RelativeTo = Enum.ActuatorRelativeTo.World
vel.VelocityConstraintMode = Enum.VelocityConstraintMode.Plane
vel.PrimaryTangentAxis = Vector3.new(1,0,0)
vel.SecondaryTangentAxis = Vector3.new(0,0,1)

vel.Attachment0 = attachment
vel.Parent = char
vel.MaxForce = 10000
--humanoid.PlatformStand = true

RunService.Stepped:Connect(function(time, dt)
	local moveDir = humanoid.MoveDirection
	print((rootPart.AssemblyLinearVelocity*Vector3.new(1,0,1)).Magnitude)
	vel.PlaneVelocity = Vector2.new(moveDir.X, moveDir.Z)*25
end)
11 Likes

Alternatively you can make a custom character controller which allows you to disable friction and such.

I have released an example with a press and hold F to slide mechanic.

1 Like

Thanks, LinearVelocity worked. I just had to set the ConstraintMode to Line, set the MaxForce to something big, and set the direction to the initial LookVector and it worked perfectly.

2 Likes

and if I wanted to have Y but at somepoint to have it as gravity?

Use a line mode in the y axis to have linear force in the y axis, then disable it if you want to have normal gravity happening.

1 Like

Do you know any way to kinda balance gravity on lineForce?

1 Like