How do i fix my wheel friction on a raycast suspension car?

  1. What do you want to achieve? Keep it simple and clear!

I was following a tutorial on how to make raycast car supension by krokosha666:

Raycast Car Suspension By Krokosha666

i want to create a suspension thats stable and not glitchy.

  1. What is the issue? Include screenshots / videos if possible!

around the timestamp of 2.50 of the tutorial, i got stuck because the friction on the rightvector of the car doesnt work, keep in mind the car is just a simple floating brick, the script is on serverscriptservice.

when i test on run mode at studio, i change the X assemblylinearvelocity of the car from 0 to 10 and it gave 8.039.. and so on and just kept moving on the x axis, and yes the car is oriented correctly set at coordinates(0,0,0).


and the weird thing is when i set the wheel friction to a high value like 120 it travels at insane speed:

  1. **What solutions have you tried so far?

i didnt know how to fix it so i asked chatgpt but it just gave the same result,

this is my code:

ignore the coroutine cuz i didnt even call it, i just adjusted some stuff.
BTW my car mass is 1152 if thats necessary

local car = Workspace.RayCar

local WheelPosition = {FL = Vector3.new(-2, -1, -4), FR = Vector3.new(2, -1, -4), RL = Vector3.new(-2, -1, 4), RR = Vector3.new(2, -1, 4)}

local WheelSuspLengthMemory = {}

local filterTable = {car}

for i, v in pairs(WheelPosition) do WheelSuspLengthMemory[i] = 0.5 end

local SuspMaxLength = 1.3
local WheelRadius = 0.5

local Stiffness = 1200
local Damper =  100

local wheelFriction = 50

--local visRay = false

car:SetNetworkOwner(nil)

while true do
	local delta = game["Run Service"].Heartbeat:Wait()
	
	for wheelName, origin in pairs(WheelPosition) do
		local carCF = car.CFrame
		local rayOrigin = carCF:ToWorldSpace(CFrame.new(origin)).Position
		local rayDir = -carCF.UpVector * (SuspMaxLength + WheelRadius)
		local rayParams = RaycastParams.new()
		rayParams.FilterType = Enum.RaycastFilterType.Exclude
		rayParams.FilterDescendantsInstances = filterTable
		rayParams.IgnoreWater = true
		local raycast = workspace:Raycast(rayOrigin, rayDir, rayParams)
		
		if raycast  then
			local rayDist = (rayOrigin - raycast.Position).Magnitude
			local SpringLength = math.clamp(rayDist - WheelRadius, 0, SuspMaxLength)
			local stiffnessForce = Stiffness * (SuspMaxLength - SpringLength)
			local damperForce = Damper * ((WheelSuspLengthMemory[wheelName] - SpringLength) / delta)
			local suspForce = carCF.UpVector * (stiffnessForce + damperForce)
			local RotWheelDirCFrame = CFrame.lookAt(Vector3.zero, carCF.LookVector, carCF.UpVector)
			local LocalVel = RotWheelDirCFrame:ToObjectSpace(CFrame.new(car:GetVelocityAtPosition(raycast.Position)))
			
			local xForce = carCF.RightVector * -LocalVel.X * wheelFriction
			WheelSuspLengthMemory[wheelName] = SpringLength
			
			car:ApplyImpulseAtPosition(suspForce + xForce, raycast.Position)
		end
		
		coroutine.wrap(function()
			local p = Instance.new("Part", workspace)
			
			table.insert(filterTable, p)
			
			p.Name = 'rayVis'
			p.Color = raycast and Color3.new(0,0,1) or Color3.new(1,0,0)
			p.Anchored = true
			p.CanCollide = false
			p.Material = Enum.Material.Neon
			local npos = raycast and raycast.Position or rayOrigin + rayDir
			local rdist = (npos - rayOrigin).Magnitude
			p.Size = Vector3.new(rdist, 0.1,0.1)
			p.Shape = Enum.PartType.Cylinder
			local s = rayOrigin - carCF.UpVector * rdist/2
			p.CFrame = CFrame.lookAt(s, s + carCF. RightVector, -carCF.LookVector)

			for i = 10, 1, -1 do
				local delta = game["Run Service"].Heartbeat:Wait()
				p.Transparency = (i)
			end
		end)
	end
end

so guys, i think this is a studio bug, its fixed after i update to the latest version 699 heh

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.