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:
And I’m also using a BodyGyro to align the character:
And yes, I did modify some of the properties to try and resolve this problem,
but no luck.
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!
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.
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.
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)