I’m trying to calculate the a force against the slope.
Ignore the weird objects flying, this may be my 13th time trying to resolve this issue.
I’ve desperately tried to use Mathematical and Physical Formulas to fix this however it either shakes like crazy or just continues slipping.
Code
local rightVector = attCF.RightVector
local lookVector = attCF.LookVector
local normal = Raycast.Normal
local hit = Raycast.Position
local contactPart = Raycast.Instance
local projectedForward = (lookVector - lookVector:Dot(normal) * normal).Unit
local right = projectedForward:Cross(normal).Unit
local forward = normal:Cross(right).Unit
local rot = CFrame.fromMatrix(Vector3.zero, right, normal, forward)
FloorAtt.WorldCFrame = CFrame.new(hit) * rot
local displacement = math.max(SpringLength - Raycast.Distance, SpringMin)
local velocity = RootVelocity:Dot(normal)
-- Suspension
local springForce = displacement * SpringStiffness
local dampingForce = SpringDampening * velocity
local netForce = Mass * (springForce - dampingForce)
local platformVel = contactPart and contactPart:GetVelocityAtPosition(hit) or Vector3.zero
local rawVel = Root:GetVelocityAtPosition(hit)
local rawVelLocal = attCF:VectorToObjectSpace(rawVel)
local relVel = rawVel - platformVel
local relVelLocal = attCF:VectorToObjectSpace(relVel)
-- Friction
local floorAttCF = FloorAtt.WorldCFrame
local floorRawVelLocal = floorAttCF:VectorToObjectSpace(rawVel)
local floorRelVelLocal = floorAttCF:VectorToObjectSpace(relVel)
local worldUp = Vector3.yAxis
local slopeAngle = math.acos(math.clamp(normal:Dot(worldUp), -1, 1))
local slopeFixAngle = math.abs(math.rad(90 - math.deg(slopeAngle)))
local slopeDeg = math.deg(slopeAngle)
local normalForce = netForce
local moveForce = Mass * workspace.Gravity * math.sin(slopeDeg)
local fallForce = Mass * workspace.Gravity * math.cos(slopeDeg)
local lateralForce = -floorRelVelLocal.X * Mass
local longitudinalForce = floorRelVelLocal.Z * Mass
local floorRightVector = floorAttCF.RightVector
local floorLookVector = floorAttCF.LookVector
local F = ((floorRightVector * lateralForce) + (floorLookVector * longitudinalForce))/No_Attachments

