How could I change my raycast car's grip based on it's drift angle?

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to find a better way to apply drifting to a raycast car I’ve been working on.

  2. What is the issue? Include screenshots / videos if possible!
    –The car likes to slide partially sideways after drifting.


    –The wheels always have the same friction no matter the drift angle.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve looked but finding info on this has been quite hard. Although I found a video I am aiming at https://twitter.com/i/status/1121741075301851141
    At around 28 seconds into the video, the car changes the friction as the car curves more.

More details and a better explanation:

Currently, my code looks like this:

local function getPointVelocity(object, point)
	return object.Velocity + object.RotVelocity:Cross(point - object.Position)
end

local pointVelocity = getPointVelocity(Car.Body, part.Position)

local u = pointVelocity
local v = Car.Body.CFrame:VectorToObjectSpace(Vector3.new(0,0,1))
local a = (u*v/v.Magnitude^2)*v --This is a vector at the wheel's ground

local DriftForce = a * GripMultiplier --Drift
local DriftForwardForce = Car.Body.CFrame.XVector * DriftForce.magnitude * .25 -- Moves car forward from drift

Car.Body["Drift"..part.Name].Force = -DriftForce --Drift
Car.Body["DriftForward"..part.Name].Force = DriftForwardForce --Forward force from drift

//Here is my demo file: Project Zentorno.rbxl (114.6 KB)

Is there a better formula that would include changing the car’s grip multiplier depending on the drift angle and remove the weird sideways movements? Also, I assume if the grip changes the greater the angle that the sideways movement would be removed?