i have been working on making skis for roblox. but i have difficulties with the player shaking while going down hill
local character = script.Parent
local rootPart = character:WaitForChild("HumanoidRootPart")
local humanoid = character:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
local SKI_SPEED = 40
local RAY_DISTANCE = 5
character.Animate:Destroy()
RunService.RenderStepped:Connect(function()
if not character or not rootPart then return end
local rayOrigin = rootPart.Position
local rayDirection = Vector3.new(0, -RAY_DISTANCE, 0)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local rayResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if rayResult then
local groundNormal = rayResult.Normal
-- Smoothly update the stored right vector to prevent drift
local RightVector = rootPart.CFrame.RightVector
local correctedForward = groundNormal:Cross(RightVector).Unit
-- Apply the stable vectors to the character's CFrame
local newCFrame = CFrame.fromMatrix(rootPart.Position, RightVector, groundNormal, -correctedForward)
rootPart.CFrame = newCFrame
-- Adjust velocity
local slopeAngle = math.deg(math.acos(groundNormal.Y))
if slopeAngle > 5 then
rootPart.AssemblyLinearVelocity = correctedForward * SKI_SPEED
else
rootPart.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
end
end
end)
Any help would be appreciated