How to detect if a player is sliding up a wedge in a sliding system?

I’m to create a sliding system for my game, but I need a way to detect if the player is going up the wedge so that they can’t just slide back up and only down.

Example of problem:
https://gyazo.com/53be44884be852ac8277de2e0d5701e5

For a full answer, we’d need to see the code of the sliding system. But off the bat, you could probably just get the lookvector or velocity vector and see if the y component is positive.

Yeah I’ve tried using lookvector but I don’t know where to go from there

local Players = game:GetService('Players')
local player = Players:GetPlayerFromCharacter(script.Parent.Parent.Parent)
local Character = player.Character
local tiltFunction

local slidesound = script.Slide:Clone()
local vel = Instance.new("BodyVelocity")
vel.Parent = nil
script.Parent.OnServerEvent:Connect(function(Player,on)
	Player.Character.Sliding.Value = on
	local ray = Ray.new(player.Character.HumanoidRootPart.CFrame.p, Vector3.new(0,-10,0), params)
	if on then
		slidesound.Parent = Character.HumanoidRootPart
		slidesound:Play()
		tiltFunction = game["Run Service"].Heartbeat:Connect(function()
			local hit, position, normal = workspace:FindPartOnRay(ray, game.Workspace.Alive)
			if hit and hit.Anchored == true and hit.CanCollide == true and hit.Transparency ~= 1  and hit.Name == "CanSlide" then
			local params = RaycastParams.new()
			params.FilterDescendantsInstances = {player.Character}
			params.FilterType = Enum.RaycastFilterType.Blacklist
			local Direction = player.Character.HumanoidRootPart.CFrame.LookVector
			vel.MaxForce = Vector3.new(math.huge,20,math.huge)
			vel.Parent = Character.HumanoidRootPart
			vel.Velocity = Character.HumanoidRootPart.CFrame.LookVector * 25
				vel.Name  =  "slidevel"
				if ray then
					local vector = player.Character.HumanoidRootPart.CFrame:VectorToObjectSpace(normal)
					player.Character.LowerTorso.Root.C0 = CFrame.new(0,-1,0,1,0,0,0,1,0,0,0,1) * CFrame.Angles(vector.z, 0, -vector.x)
				end
			end
		end)
	else
		tiltFunction:Disconnect()
		vel.Parent = nil
		slidesound:Stop()
		player.Character.LowerTorso.Root.C0 = CFrame.new(0,-1,0,1,0,0,0,1,0,0,0,1) * CFrame.Angles(0, 0, 0)
end
end)
  • I don’t think lookvector could work because there will be different hills facing different direction

It looks like 25 is your sliding speed. You could try replacing that number with

local speed = math.clamp(lookVector.y, -1, 0) * -25

This will base the speed off of the lookvector’s Y component, and is clamped to 0 if it would be going uphill.

Now it’s going very slow both uphill and downhill, not exactly sure where to put the speed

local slidesound = script.Slide:Clone()
local vel = Instance.new("BodyVelocity")
vel.Parent = nil
script.Parent.OnServerEvent:Connect(function(Player,on)
	Player.Character.Sliding.Value = on
	local ray = Ray.new(player.Character.HumanoidRootPart.CFrame.p, Vector3.new(0,-10,0), params)
	if on then
		slidesound.Parent = Character.HumanoidRootPart
		slidesound:Play()
		tiltFunction = game["Run Service"].Heartbeat:Connect(function()
			local hit, position, normal = workspace:FindPartOnRay(ray, game.Workspace.Alive)
			if hit and hit.Anchored == true and hit.CanCollide == true and hit.Transparency ~= 1  and hit.Name == "CanSlide" then
			local lookVector = Character.HumanoidRootPart.CFrame.LookVector
			local speed = math.clamp(lookVector.y, -1, 0) * -25
			local params = RaycastParams.new()
			params.FilterDescendantsInstances = {player.Character}
			params.FilterType = Enum.RaycastFilterType.Blacklist
			vel.MaxForce = Vector3.new(math.huge,20,math.huge)
			vel.Parent = Character.HumanoidRootPart
			vel.Velocity = Character.HumanoidRootPart.CFrame.LookVector * speed
			vel.Name  =  "slidevel"
				if ray then
					local vector = player.Character.HumanoidRootPart.CFrame:VectorToObjectSpace(normal)
					player.Character.LowerTorso.Root.C0 = CFrame.new(0,-1,0,1,0,0,0,1,0,0,0,1) * CFrame.Angles(vector.z, 0, -vector.x)
				end
			end

		end)
	else
		tiltFunction:Disconnect()
		vel.Parent = nil
		slidesound:Stop()
		player.Character.LowerTorso.Root.C0 = CFrame.new(0,-1,0,1,0,0,0,1,0,0,0,1) * CFrame.Angles(0, 0, 0)
end
end)

Nevermind, it’s just going slow downhill

Black Leaf - Roblox Studio (gyazo.com) i tried making it higher and this is what happens

try to make it so that if your y velocity changes positively (or if your y velocity is positive over a certain amount) then you can just cancel the slide

The size of the hills wont all be the same so that wont work

Another solution I was thinking of was that if they face that way it’ll make the character turn around but I don’t know how i’d do that

it doesnt matte rthe size of the hill, it only matters on the players velocity. If the y velocity is over, say .1 for example, then it will execute certain code

local hrp = Player.Character.HumanoidRootPart
local function CheckVelocity()
   if hrp.Velocity.Y >= .1 then
      --your code here
   end
end

game:GetService("RunService"):Connect(CheckVelocity)

if its in a server script then just put it in a while wait loop or a coroutine depending on your needs

2 Likes

thanks i didnt know this, it works now