How to prevent LinearVelocity from sticking into walls?

So, I am trying to add sliding to my action game using LinearVelocity, and I kind of run into a problem where, if I have to describe it, it’s forcefully trying to ram into the walls, instead of just falling to the ground

This is where I set up the velocity:

local MovementVelocity = Instance.new("LinearVelocity")
	MovementVelocity.Name = "MovementVelocity"
	MovementVelocity.Parent = HRP
	MovementVelocity.Attachment0 = MovementAttachment
	MovementVelocity.RelativeTo = Enum.ActuatorRelativeTo.World
	
	local CheckValue = HRP.AssemblyMass * 5000
	
	MovementVelocity.ForceLimitsEnabled = true
	MovementVelocity.ForceLimitMode = Enum.ForceLimitMode.PerAxis
	MovementVelocity.MaxAxesForce = Vector3.new(CheckValue, 0, CheckValue)

and this is the main just in case

	local CurrentVelocity = HRP.AssemblyLinearVelocity.Magnitude
	
	SlideConnection = RunService.Heartbeat:Connect(function(dt)
		if SlideStrength <= 0 then
			WM.StopSlide(Character)
		else
			Vel.VectorVelocity = Vector3.new(
				HRP.CFrame.LookVector.X * SlideStrength,
				workspace.Gravity / 2,
				HRP.CFrame.LookVector.Z * SlideStrength
			)
			
			SlideStrength -= 0.98 * dt
		end
	end)

Any help is appreciated!

i see two options:

  1. detect touch with wall and disable the force
  2. track linear velocity of the character and if the force is enabled and if this velocity is small then disable the force
1 Like

Ok so easy option would be to detect if the vehicle touches the wall via raycasting. raycast cuz its based on direction and i think its lighter than a spatial query method like getpartsboundsinbox. dont use a touched event because if you’re driving at fast speeds the touched event is unreliable. it wont detect sometimes.

2 Likes

when using Enum.VelocityConstraintMode.Vector3 the linearvelocity will simply not care about gravity

Instead try using Enum.VelocityConstraintMode.Plane and set PrimaryTangentAxis’s X value to 1 and the SecondaryTangentAxis’s Z value to 1

you can also use line but it’s up to you really

2 Likes