userInputService.InputEnded:connect(function(h,n)if h.KeyCode==Enum.KeyCode.W then if movement.Y==1 then movement=Vector2.new(movement.X,0)end elseif h.KeyCode==Enum.KeyCode.A then if movement.X==-1 then movement=Vector2.new(0,movement.Y)end elseif h.KeyCode==Enum.KeyCode.S then if movement.Y==-1 then movement=Vector2.new(movement.X,0)end elseif h.KeyCode==Enum.KeyCode.D then if movement.X==1 then movement=Vector2.new(0,movement.Y)end end end)local h=0 local n=0 local i=0 for h,n in pairs(car:GetChildren())do if n:IsA("\066\097\115\101\080\097\114\116")then i=i+n:GetMass()*196.2 end end h=i*stats.Suspension.Value n=h/stats.Bounce.Value local o=Instance.new("\066\111\100\121\086\101\108\111\099\105\116\121",car.Chassis)o.velocity=Vector3.new(0,0,0)o.maxForce=Vector3.new(0,0,0)local c=Instance.new("\066\111\100\121\065\110\103\117\108\097\114\086\101\108\111\099\105\116\121",car.Chassis)c.angularvelocity=Vector3.new(0,0,0)c.maxTorque=Vector3.new(0,0,0)local O=0 local function l(i)local o=i:FindFirstChild("\066\111\100\121\084\104\114\117\115\116")if not o then o=Instance.new("\066\111\100\121\084\104\114\117\115\116",i)end local c,l=Raycast.new(i.Position,i.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0))*stats.Height.Value)local L=(l-i.Position).magnitude if c and c.CanCollide then o.force=Vector3.new(0,(stats.Height.Value-L)^2*(h/stats.Height.Value^2),0)local c=(i.CFrame:toObjectSpace(CFrame.new(i.Velocity+i.Position))).p*n o.force=o.force-Vector3.new(0,c.Y,0)else o.force=Vector3.new(0,0,0)end local E=i:FindFirstChild("\087\104\101\101\108\087\101\108\100")if E then E.C0=CFrame.new(0,-math.min(L,stats.Height.Value*.8)+E.Part1.Size.Y/2,0)local h=car.Chassis.CFrame:inverse()*i.CFrame local n=car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)if h.Z<0 then local h=1 if n.Z>0 then h=-1 end E.C0=E.C0*CFrame.Angles(0,(car.Chassis.RotVelocity.Y/2)*h,0)end E.C0=E.C0*CFrame.Angles(O,0,0)end end
-- Input end
userInputService.InputEnded:connect(function(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.W then
		if movement.Y == 1 then
			movement = Vector2.new(movement.X, 0)
		end
	elseif inputObject.KeyCode == Enum.KeyCode.A then
		if movement.X == -1 then
			movement = Vector2.new(0, movement.Y)
		end
	elseif inputObject.KeyCode == Enum.KeyCode.S then
		if movement.Y == -1 then
			movement = Vector2.new(movement.X, 0)
		end
	elseif inputObject.KeyCode == Enum.KeyCode.D then
		if movement.X == 1 then
			movement = Vector2.new(0, movement.Y)
		end
	end
end)

local force = 0
local damping = 0

local mass = 0

for i, v in pairs(car:GetChildren()) do
	if v:IsA("BasePart") then
		mass = mass + (v:GetMass() * 196.2)
	end
end

force = mass * stats.Suspension.Value
damping = force / stats.Bounce.Value

local bodyVelocity = Instance.new("BodyVelocity", car.Chassis)
bodyVelocity.velocity = Vector3.new(0, 0, 0)
bodyVelocity.maxForce = Vector3.new(0, 0, 0)

local bodyAngularVelocity = Instance.new("BodyAngularVelocity", car.Chassis)
bodyAngularVelocity.angularvelocity = Vector3.new(0, 0, 0)
bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)

local rotation = 0

local function UpdateThruster(thruster)
	--Make sure we have a bodythrust to move the wheel
	local bodyThrust = thruster:FindFirstChild("BodyThrust")
	if not bodyThrust then
		bodyThrust = Instance.new("BodyThrust", thruster)
	end
	--Do some raycasting to get the height of the wheel
	local hit, position =
		Raycast.new(thruster.Position, thruster.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * stats.Height.Value)
	local thrusterHeight = (position - thruster.Position).magnitude
	if hit and hit.CanCollide then
		--If we're on the ground, apply some forces to push the wheel up
		bodyThrust.force =
			Vector3.new(0, ((stats.Height.Value - thrusterHeight) ^ 2) * (force / stats.Height.Value ^ 2), 0)
		local thrusterDamping = thruster.CFrame:toObjectSpace(CFrame.new(thruster.Velocity + thruster.Position)).p
			* damping
		bodyThrust.force = bodyThrust.force - Vector3.new(0, thrusterDamping.Y, 0)
	else
		bodyThrust.force = Vector3.new(0, 0, 0)
	end

	--Wheels
	local wheelWeld = thruster:FindFirstChild("WheelWeld")
	if wheelWeld then
		wheelWeld.C0 =
			CFrame.new(0, -math.min(thrusterHeight, stats.Height.Value * 0.8) + (wheelWeld.Part1.Size.Y / 2), 0)
		-- Wheel turning
		local offset = car.Chassis.CFrame:inverse() * thruster.CFrame
		local speed = car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)
		if offset.Z < 0 then
			local direction = 1
			if speed.Z > 0 then
				direction = -1
			end
			wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(0, (car.Chassis.RotVelocity.Y / 2) * direction, 0)
		end
		wheelWeld.C0 = wheelWeld.C0 * CFrame.Angles(rotation, 0, 0)
	end
end
