Sliding mechanism help (R6)

  1. I want to make it so the player actually slides according to the slope (for example if the player is sliding down on a wedge, it’s body will also face the slope of the wedge.)

  2. I have spent for the last 5-7 hours of the day (which is now midnight) trying to figure out how to make the player actually slide and face it, I have failed countless amounts of times making not much of a progress.

A GIF regarding of it: https://gyazo.com/40f02ea893db8a89e1ae6e69c23ac37c

  1. I have looked through the devforum, I have found several articles regarding of sliding mechanism’s slope and none of them really helped with the issue, I have tried using the root’s CFrame or even BodyGyro and none worked even though the method was supposedly the right one for it or at least I think it was the right one.

The script itself:

local Event = game:GetService("ReplicatedStorage"):WaitForChild("Signals").SlideEvent
local Gyro = Instance.new("BodyGyro")
local Velocity = Instance.new("BodyVelocity")
Event.OnServerEvent:Connect(function(player, character, rayPosition, rayNormal)
	Gyro.Parent = character:WaitForChild("HumanoidRootPart")
	local vector = player.Character.HumanoidRootPart.CFrame:VectorToObjectSpace(rayNormal)
	Gyro.CFrame = CFrame.new(character:WaitForChild("HumanoidRootPart").Position, character:WaitForChild("HumanoidRootPart").Position + rayNormal)
	Gyro.MaxTorque = Vector3.new(0, math.huge, 0 )
	Velocity.MaxForce = Vector3.new(math.huge,20,math.huge)
	Velocity.Parent = character.HumanoidRootPart
	Velocity.Velocity = character.HumanoidRootPart.CFrame.LookVector * 2
	character:WaitForChild("Humanoid").AutoRotate = false
	character:WaitForChild("Humanoid").HipHeight = -2
end)
1 Like

Don’t worry about it, CFrame takes months to learn and even now I’m still learning about it.

Egomoose has a platformer character controller with a slide feature

This is the angle calculation method I believe was used in the project.

@T34P07D3V was able to get results using this method for a similar sliding system:

4 Likes

Yeah, I have found that out last night, although I would really like to actually understand and learn how it’s done and how it actually works as just straight up copying wouldn’t be much of a use. I have also watched a bit of tutorial regarding of CFrame, I believe the randomAxis (Vector3.new(1,0,0)) is the right vector in worldspace I believe, but what about the rest? The getrotationbetween sounds complex, I don’t really understand it at all same with rotatetofloorcframe and why is lerp only to half? I really do suck with math and I can’t make sense of such, I always had issues with such mathematics lol, I apologize for my stupidity, but it’s my first time actually doing such complex calculations and CFrame related stuff.

1 Like

By the way, do I have to use something else other than while true do loop? Maybe the example which was given (HeartBeat one) or should I just do it with the loop I am using right now?

1 Like

I think you should spend more time and find the answers to these questions yourself.

I’ll answer them for the time being when I have the time at this moment.

This is up to you, the only difference is when the code runs and how often the code runs in the task scheduler see the task scheduler diagram. Usually the order the code runs only matters in certain cases such as overwriting animations using .Stepped in Motor6D.Transform.

In fact task.wait() is the same as heartbeat.

If no duration is given, it will default to zero (0). This means the thread resumes on the very next step, which is equivalent in behavior to RunService.Heartbeat:Wait()

The lerp was just used to animate the CFrame and show the rotation taking place, purely visual effect.

It is complex and I admit I do not understand it fully.

I only know the concept that you input 2 vectors and the output is a rotation CFrame in world space that will rotate the CFrame to orientate the previous vector towards the goal such as wedge example.

The reason it is in world space is that the multiplication is applied before the CFrame and not after. CFrame order matters a lot and I tried to put some examples in my tutorial.

2 Likes

Alright thank you, I’ll continue trying and figuring it out, currently this is the situation regarding of sliding: Movement. - Roblox Studio (gyazo.com)

I have no idea what’s going on, I think it is related to the positioning of the rootpart and I also believe that the calculation turns worldspace into objectspace if I am correct of course, not too sure.

As for the current state of the script it’s pretty messy

Script :

local function getRotationBetween(u, v, axis)
    local dot, uxv = u:Dot(v), u:Cross(v)
    if (dot < -0.99999) then return CFrame.fromAxisAngle(axis, math.pi) end
    return CFrame.new(0, 0, 0, uxv.x, uxv.y, uxv.z, 1 + dot)
end

Event.OnServerEvent:Connect(function(player, character, rayPosition, rayNormal, dt, TestPart)
    local rotateToFloorCFrame = getRotationBetween(character:WaitForChild("HumanoidRootPart").CFrame.UpVector,rayNormal,randomAxis)
    local goalCF = rotateToFloorCFramecharacter:WaitForChild("HumanoidRootPart").CFrame
    character.HumanoidRootPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(goalCF, 5 dt).Rotation + character.HumanoidRootPart.CFrame.Position
    TestPart.CFrame = character.HumanoidRootPart.CFrame:Lerp(goalCF, 5 * dt).Rotation + character.HumanoidRootPart.CFrame.Position
    TestPart.Parent = character
end)
1 Like

Yeah, perfect solution, I have made it work on a part but it doesn’t work on my script, I’ll figure out why, but at least it’s solved. Thank you very much regarding of the issue which might have caused a nuisance upon you, I apologize deeply about it, but I am very thankful and grateful for your help. You have my gratitude.

2 Likes

I believe the simplest solution to the problem is to use the rootjoint (the motor6d of the root) it does work fabulously and it’s probably the best choice that I have considering the CFrame part sounds way more complex using the rootpart so this is a simpler solution to it I believe. Not too sure if it’s a solution of the sliding mechanism though, considering the fact that whenever I use the humanoidrootpart it bugs out pretty badly nonstop for some reason even though it works for a part, but starts glitching when it comes to the character of the player

1 Like

Hello, sorry to disturb you, but it’s nearly done like very close to being done! I have found a article regarding of the sliding mechanism too which helped drastically with the motor6d, it’s nearly done but it’s facing the wrong way for some reason. Do you maybe know how to fix this or know any other method regarding of how to fix it? (rotation basically)

(The red line is where it is facing, blue line is how I want it to face basically it to be reversed (180 degrees of turn I believe)

Image:

1 Like

Probably just multiply by CFrame.Angles() somewhere in your code to reverse it.

Also if you encounter a collision issue perhaps you can follow the PlatformerCharacterController which turns the character into a sphere when sliding. Perhaps I should use this for my game as well.

1 Like

Yeah, hopefully I’ll figure it out considering that I am getting pretty tired of trying to figure this out considering how much time it has consumed. By the way, I looked at your profile and I noticed that we both have pretty similar professions which is pretty cool in my opinion I believe. I am really sorry once again that I am taking so much of your time over my stupidity and lack of knowledge + intel towards such subject.

2 Likes

Hello, I just wanted to inform you that I found a tutorial regarding of it and it’s really helpful! I learnt that the Z vector is actually inverted in R6, which is really confusing, but ey at least it’s a solution and explanation regarding of how it’s done! Here’s the guy’s messages regarding of the slope mechanism (it’s a bit sloppy, but it’s fine, I managed to fix it a little anyway)

in the cframe.angles parts, the vector.z needs to be negative since it’s inverted of R15

This was his response regarding of another mathematical equation:
no, im trying to avoid the player’s feet from floating in mid-air, so theres a reason why i added a negative sign to the vector.z as you can see in the video.

The video: (299) How to Make a Slope Tilting System | Roblox Studio [R6] - YouTube

The script itself that I modified a little:

local char = game:GetService("Players").LocalPlayer.Character
local HRP = char:WaitForChild("HumanoidRootPart")
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {char:GetChildren(),char}
while true do
	local r = workspace:Raycast(HRP.Position,Vector3.new(0,-5,0),Params)
	if r then
		local vector = HRP.CFrame:VectorToObjectSpace(r.Normal)
		if vector.z > 0 then
			HRP.RootJoint.C0 = CFrame.new(0,vector.z * 1.25,0,-1,0,0,0,0,1,0,1,0) * CFrame.Angles(-vector.z,0,-vector.x)
		else
			HRP.RootJoint.C0 = CFrame.new(0,-vector.z * 1.25,0,-1,0,0,0,0,1,0,1,0) * CFrame.Angles(-vector.z,0,-vector.x)
		end
	end
	task.wait(0.01)
end
1 Like