Hello guys! So I was trying to make realistic sliding system and… when players go up a slope, it literally speeds up
I do not know how to fix this
This sliding system uses raycast for speed
Main codes:
script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed = 25
animation:Play()
while true do
local rayOrigin = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
local rayDestination = game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3.new(0, -10000, 0)
local rayDirection = rayDestination - rayOrigin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local y = raycastResult.Normal.Y
if y == 1 then
script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed -= 0.10
elseif y < 1 then
script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed += 0.07
end
if script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed <= 0 or game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection.Magnitude <= 0 then
animation:Stop()
break
end
end
task.wait(0)
end
(Its poorly made lol)
Idk I’m bad at english so there could be some grammar issues
uis = game:GetService("UserInputService")
animation = game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(script:WaitForChild("sliding"))
animation.Priority = Enum.AnimationPriority.Action4
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C and script.Parent.running.Value == true then
script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed = 25
animation:Play()
while true do
local rayOrigin = game.Players.LocalPlayer.Character.HumanoidRootPart.Position
local rayDestination = game.Players.LocalPlayer.Character.HumanoidRootPart.Position + Vector3.new(0, -10000, 0)
local rayDirection = rayDestination - rayOrigin
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.IgnoreWater = true
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
local y = raycastResult.Normal.Y
if y == 1 then
script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed -= 0.10
elseif y < 1 then
script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed += 0.07
end
if script.Parent:FindFirstChildOfClass("Humanoid").WalkSpeed <= 0 or game.Players.LocalPlayer.Character:FindFirstChildOfClass("Humanoid").MoveDirection.Magnitude <= 0 then
animation:Stop()
break
end
print(y)
end
task.wait(0)
end
end
end)
i may just be dumb and what you’re doing works but i feel like you have to use angles to detect if a player is actually going up or down not just the vector