Slope alignment clipping

Hey devs!

I’ve been trying to make slope alignment for my sonic physics engine, and I’m really
close to it.

A problem that’s been holding me back from continuing is the little leg clipping
as seen below:

image

And I’m also using a BodyGyro to align the character:

image

And yes, I did modify some of the properties to try and resolve this problem,
but no luck. :frowning_face:

Code:

runService.Heartbeat:connect(function()
	local direction = Vector3.new(0, -4, 0)
	local ray = game.Workspace:Raycast(rootpart.Position, direction, raycastParams)
	
	if ray then
		local hit, pos, normal = ray.Instance, ray.Position, ray.Normal
		
		if hit then			
			local p1 = rootpart.CFrame.LookVector:Cross(normal)
			bodyGyro.CFrame = CFrame.fromMatrix(rootpart.Position, p1, normal)
		end
	end
end)

Note: I took the code somewhere in devforum and modified it to my needs.
Thanks in advance! :smiley:

Bump as it’s been nearly an hour and I really need this for my game. :slightly_frowning_face:

I looked at your image but can’t tell what you are seeing as a problem.

If it the feet in the grass or the angle of the torso?

It is the feet clipping through the grass.

I see feet clipping issues all the time in games.

I think it’s just a Roblox thing.

If you look, sometimes you will see that you’re standing above the ground also.

You can adjust the character hip height setting to fix the floating issue.

I’ll try this tomorrow, thanks for the response. :slightly_smiling_face:

I have made a system similar to this for one of my other games and I have the same question!

However, instead of using BodyGyro I just modify the CFrame of the root weld. From there, I can make adjustments to the height of the root weld. My question is how much or how little?

My advice is to somehow modify the root joint / root weld’s C0 property to compensate for height.

Did you manage to solve this problem? If so, how?

I didn’t manage to solve the problem. I do know you need to move the character outwards from the normal of the hill, so you need to change the position of the character somehow.

Alright, so I managed to somewhat solve the problem, but the only thing that sucks is that you kinda have to make your own custom movement.

image

The script in case if anyone interested:

local runService = game:GetService("RunService")

local player = game.Players.LocalPlayer
local character = player.Character

local humanoid = character:WaitForChild("Humanoid")
local rootpart = humanoid.RootPart

local bodyGyro = script:WaitForChild("BodyGyro")
bodyGyro.CFrame = rootpart.CFrame
bodyGyro.Parent = rootpart

local bodyVelocity = script:WaitForChild("BodyVelocity")
bodyVelocity.Parent = rootpart

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {character}
raycastParams.IgnoreWater = true

humanoid.PlatformStand = true

runService.RenderStepped:connect(function(delta)
	local direction = Vector3.new(0, -10, 0)
	local ray = game.Workspace:Raycast(rootpart.Position, direction, raycastParams)
	
	if ray then
		local hit, pos, normal = ray.Instance, ray.Position, ray.Normal
		
		if hit then			
			local p1 = rootpart.CFrame.LookVector:Cross(normal)
			bodyGyro.CFrame = CFrame.fromMatrix(rootpart.Position, p1, normal)
		end
	end
	
	bodyVelocity.Velocity = humanoid.MoveDirection * humanoid.WalkSpeed
end)

image

image

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.