Hello I’m keepin it short. I made a raycast susp system. My Raycast’s are When I throttle The car part stays back and raycast’es go off. Ill post a vid.
local car = script.Parent
local body = car.Body
local seat = car:FindFirstChildWhichIsA("VehicleSeat")
local wheelsFolder = car:FindFirstChild("Wheels")
body:SetNetworkOwner(nil)
if wheelsFolder then
for _, v in pairs(wheelsFolder:GetChildren()) do
if v:IsA("BasePart") then
v:SetNetworkOwner(nil)
v.CanCollide = false
v.Anchored = false
end
end
end
local config = {
suspensionMaxLength = 2,
wheelRadius = 0.5,
stiffness = 5500,
damper = 170,
frontFriction = 1.8,
rearFriction = 1.2,
engineForce = -2000,
maxSteerAngle = 0.5,
maxSpeed = 80,
}
local wheelOffsets = {
FL = Vector3.new(-4, 0, 7),
FR = Vector3.new( 4, 0, 7),
RL = Vector3.new(-4, 0, -7),
RR = Vector3.new( 4, 0, -7),
}
local prevLengths = {}
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {car}
rayParams.FilterType = Enum.RaycastFilterType.Exclude
game["Run Service"].Heartbeat:Connect(function(delta)
local throttle = seat and seat.Throttle or 0
local steer = seat and seat.Steer or 0
for wheelName, offset in pairs(wheelOffsets) do
local rayOrigin = body.CFrame:PointToWorldSpace(offset)
local rayDir = -body.CFrame.UpVector * (config.suspensionMaxLength + config.wheelRadius)
local result = workspace:Raycast(rayOrigin, rayDir, rayParams)
local wheelModel = wheelsFolder and wheelsFolder:FindFirstChild(wheelName)
if result then
local dist = (rayOrigin - result.Position).Magnitude
local springLength = math.clamp(dist - config.wheelRadius, 0, config.suspensionMaxLength)
if not prevLengths[wheelName] then prevLengths[wheelName] = springLength end
local springVelocity = (prevLengths[wheelName] - springLength) / delta
local suspensionForce = body.CFrame.UpVector * ((config.suspensionMaxLength - springLength) * config.stiffness + springVelocity * config.damper)
local wheelVelocity = body:GetVelocityAtPosition(result.Position)
local isFront = (wheelName == "FL" or wheelName == "FR")
local steerAngle = isFront and (steer * config.maxSteerAngle) or 0
local wheelCFrame = body.CFrame * CFrame.Angles(0, -steerAngle, 0)
local lateralVelocity = wheelCFrame.RightVector:Dot(wheelVelocity)
local currentFriction = isFront and config.frontFriction or config.rearFriction
local frictionForce = -wheelCFrame.RightVector * lateralVelocity * (body.AssemblyMass * currentFriction)
local motorForce = Vector3.new(0,0,0)
if isFront then
local currentForwardSpeed = wheelCFrame.LookVector:Dot(wheelVelocity)
if math.abs(currentForwardSpeed) < config.maxSpeed then
motorForce = wheelCFrame.LookVector * (throttle * config.engineForce)
end
end
body:ApplyImpulseAtPosition((suspensionForce + frictionForce + motorForce) * delta, result.Position)
if wheelModel then
local visualPos = result.Position + (body.CFrame.UpVector * config.wheelRadius)
wheelModel.CFrame = wheelCFrame.Rotation + visualPos
end
prevLengths[wheelName] = springLength
else
if wheelModel then
local steerAngle = (wheelName == "FL" or wheelName == "FR") and (steer * config.maxSteerAngle) or 0
local freePos = rayOrigin - (body.CFrame.UpVector * config.suspensionMaxLength)
wheelModel.CFrame = (body.CFrame * CFrame.Angles(0, -steerAngle, 0)).Rotation + freePos
end
prevLengths[wheelName] = nil
end
end
end)
