I’ve got a code that kind of works but doesn’t work as well. I need to make it so that it would slowly set the wheel above the ground.
local RunService = game:GetService("RunService")
local model = script.Parent
local Parts = model:WaitForChild("Parts")
local WheelParts = Parts:WaitForChild("WheelParts")
local VehicleSeat = Parts:WaitForChild("VehicleSeat")
local Chassis = model:WaitForChild("Chassis")
local MoveVelocity = model:WaitForChild("MoveVelocity")
local TurnVelocity = model:WaitForChild("TurnVelocity")
local Occupant = model:WaitForChild("Occupant")
local speed = 50
local maxSteer = 100
local gravity = workspace.Gravity
local modelMass = 0
local driveConnection
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Exclude
raycastParams.FilterDescendantsInstances = {model}
for i,v in ipairs(model:GetDescendants()) do
if v:IsA("BasePart") then
modelMass += v.AssemblyMass
end
end
local function Suspension(raycastResult, wheel)
local SuspensionForce = wheel:FindFirstChild("SuspensionForce")
if SuspensionForce then
if raycastResult then
local normal = raycastResult.Normal
local force = normal * (modelMass * gravity)
SuspensionForce.Force = force
else
SuspensionForce.Force = Vector3.new()
end
end
end
local function Drive()
driveConnection = RunService.Heartbeat:Connect(function()
for _, wheel in WheelParts:GetChildren() do
if wheel:IsA("BasePart") then
local wheelRadius = wheel.Size
local rayOrigin = wheel.Position
local rayDirection = wheel.CFrame.LookVector * wheelRadius
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
--MoveVelocity.Enabled = true
TurnVelocity.AngularVelocity = Vector3.new(0, -math.rad(VehicleSeat.Steer * maxSteer), 0)
else
TurnVelocity.AngularVelocity = Vector3.new(0, 0, 0)
MoveVelocity.Enabled = false
end
Suspension(raycastResult, wheel)
end
end
end)
end
Drive()
Current Result: