Hey devs ,
I’ve made a post similar to this:
https://devforum.roblox.com/t/slope-alignment-clipping/2085632/11
But another problem I’ve run into is getting the character to face the direction
it’s moving in:
How do I do this without it interfering with the BodyGyro
that makes the character rotate up the slopes?
local runService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local rootpart = humanoid.RootPart
local collider = Instance.new("Part")
collider.Name = "Collider"
collider.Transparency = 1
collider.Shape = Enum.PartType.Ball
collider.Size = Vector3.new(2, 2, 2)
collider.Massless = true
collider.CFrame = rootpart.CFrame * CFrame.new(0, -2, 0)
collider.Parent = character
local colliderWeld = Instance.new("WeldConstraint")
colliderWeld.Name = "ColliderWeld"
colliderWeld.Part0 = collider
colliderWeld.Part1 = rootpart
colliderWeld.Parent = rootpart
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(100000, 0, 100000)
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
bodyVelocity.P = 100000
bodyVelocity.Parent = rootpart
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.MaxTorque = Vector3.new(1000000, 0, 1000000)
bodyGyro.P = 35000
bodyGyro.CFrame = rootpart.CFrame
bodyGyro.Parent = rootpart
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {character}
raycastParams.IgnoreWater = true
local colliderPhysicalProperties = PhysicalProperties.new(
0.7, -- Density
1, -- Friction
0, -- Elasticity,
1, -- FrictionWeight
1 -- ElasticityWeight
)
collider.CustomPhysicalProperties = colliderPhysicalProperties
--
humanoid.AutoRotate = false
humanoid.PlatformStand = true
--[[
Moves the character, but how do I make it face the direction
its moving without it interfering with the BodyGyro?
]]
function MoveCharacter()
local velocity = humanoid.MoveDirection * humanoid.WalkSpeed
bodyVelocity.Velocity = velocity
end
-- Slope Tilting
function AlignToSurface()
local direction = rootpart.CFrame.UpVector * -10
local ray = game.Workspace:Raycast(rootpart.Position, direction, raycastParams)
if ray then
local hit, pos, normal = ray.Instance, ray.Position, ray.Normal
local p1 = rootpart.CFrame.LookVector:Cross(normal)
bodyGyro.CFrame = CFrame.fromMatrix(rootpart.Position, p1, normal)
end
end
runService.Heartbeat:connect(AlignToSurface)
humanoid:GetPropertyChangedSignal("MoveDirection"):connect(MoveCharacter)
Any replies would help out a ton