Angling player to slopes

  1. What do you want to achieve?
    The same slope rotation as seen in this game
    Super Scuffle Indev - Roblox
    (Example images from devs themselves)
    1
    2

  2. What is the issue?
    No solution on the devforum seems to provide the same result with R6, or anything even generally close to functional (see results screenshots bellow).

  3. What solutions have you tried so far?
    Most of these pertain to R15 avatars, and ones that don’t do not work either way. Some methods use a torque or some other kind of arcane combination of physics object, but this leads to the player avatar experiencing bizarre physics byproducts
    Attempted methods:
    #1 (current)
    image
    #2 (sorry! no screenshot available)
    #3
    image

Current, non-working implementation, running on RenderStepped (#1)

	local RaycastResult = workspace:Raycast(RootPart.Position, Vector3.yAxis * -6, NonCharParams)
	if RaycastResult then
		local rotation = CFrame.new(RaycastResult.Normal, Vector3.zero) * CFrame.Angles(math.rad(90), 0, 0)
		RootJoint.C0 = DEFAULT_C0 * rotation
	else RootJoint.C0 = DEFAULT_C0 end
3 Likes

The script from this post SHOULD help you. It helped me afterall when i had the exact same problem as you!

The script

local char = script.Parent
local rootPart = char:WaitForChild("HumanoidRootPart")
local xzGyro = Instance.new("BodyGyro")
local yGyro = Instance.new("BodyGyro")
yGyro.MaxTorque = Vector3.new(0,3e5,0)
yGyro.P = 5e5
xzGyro.MaxTorque = Vector3.new(3e5,0,3e5)
xzGyro.P = 5e5
xzGyro.Parent = rootPart

while wait(0.5) do
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = {char}
	params.FilterType = Enum.RaycastFilterType.Blacklist
	local result = workspace:Raycast(rootPart.Position, Vector3.new(0,-10,0), params)
	
	yGyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + char.Humanoid.MoveDirection*10)
	
	if (result) then
		print(result.Normal)
		local currentRightVector = rootPart.CFrame.RightVector
		local upVector = result.Normal
		local newFacialVector = currentRightVector:Cross(upVector)
		xzGyro.CFrame = CFrame.fromMatrix(rootPart.Position, currentRightVector, upVector, newFacialVector)
	end
	
end

And yes, it might be old BUT it still worked perfectly.

2 Likes

I have indeed tried this one! I don’t know if this is specific difference with the games settings, but it does not function properly.

3 Likes

Hi, I see you linked my post here and just wanted to say that you can add some offset to the code to fix it. You could try doing that.

As for @Korpsii. Please do not use body gyros. They are deprecated and not a good practice at all.

2 Likes

What offset would be fit for a regular R6 avatar? I’ve attempted this before, but the best I’ve managed was to offset so that the player begins upright at flat surfaces, but when trying to walk on any kind of slope, it still orients the character incorrectly (upside down with the demonstration slope, in that case).

1 Like
local RunService = game:GetService("RunService")

local Character = script.Parent
local HumanoidRootPart:BasePart = Character:WaitForChild("HumanoidRootPart")
local RootJoint = HumanoidRootPart:WaitForChild("RootJoint")

local RootJointC0 = RootJoint.C0
local RayParams = RaycastParams.new()
RayParams.FilterDescendantsInstances = {Character}

RunService.RenderStepped:Connect(function(deltaTime)
	local RaycastResult = workspace:Raycast(HumanoidRootPart.Position,-Vector3.yAxis*5, RayParams)
	local C0Offset = CFrame.identity
	if RaycastResult then
		local upVector = RaycastResult.Normal
		local rightVector = HumanoidRootPart.CFrame.RightVector
		local backVector = -HumanoidRootPart.CFrame.LookVector
		local calculationForX = CFrame.fromMatrix(Vector3.zero,rightVector,upVector)
		local calculationForZ = CFrame.fromMatrix(Vector3.zero,backVector,upVector)
		local x = calculationForX:ToOrientation()
		local z = calculationForZ:ToOrientation()
		
		C0Offset = CFrame.Angles(x,0,z)
	end
	RootJoint.C0 = RootJoint.C0:Lerp(C0Offset*RootJointC0,deltaTime*10)
end)

This was fun.

2 Likes

While this does work a LOT better than the previous iteration, there’s still some very odd behavior and very jerky movement present.

Well I am sure you can do it yourself hmm? Or…am I suppose to do it? No offence if any. I have already provided an entire script and further helping you would just be me spoiling your path of becoming a reputable developer. So. I’ll just tell you a basic idea:

Add a torso variable on the top and rather than using -Vector3.yAxis*3 use Torso.CFrame.UpVector*-3.

2 Likes