local function a()local a,R=Raycast.new((car.Chassis.CFrame*CFrame.new(0,0,car.Chassis.Size.Z/2-1)).p,car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0,-1,0))*(stats.Height.Value+.2))if a and a.CanCollide then return true end return false end local R=camera.CameraType camera.CameraType=cameraType spawn(function()while character.Humanoid.SeatPart==car.DriveSeat do(game:GetService("\082\117\110\083\101\114\118\105\099\101")).RenderStepped:wait()if a()then if movement.Y~=0 then local a=(car.Chassis.CFrame.lookVector*movement.Y)*stats.Speed.Value car.Chassis.Velocity=car.Chassis.Velocity:Lerp(a,.1)bodyVelocity.maxForce=Vector3.new(0,0,0)else bodyVelocity.maxForce=Vector3.new(mass/2,mass/4,mass/2)end local a=car.Chassis.CFrame:vectorToWorldSpace(Vector3.new((movement.Y*stats.Speed.Value)/50,0,(-car.Chassis.RotVelocity.Y*5)*movement.Y))local R=-(car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)).unit.Z rotation=rotation+math.rad((-stats.Speed.Value/5)*movement.Y)if math.abs(R)>.1 then a=a+car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0,(-movement.X*R)*stats.TurnSpeed.Value,0))bodyAngularVelocity.maxTorque=Vector3.new(0,0,0)else bodyAngularVelocity.maxTorque=Vector3.new(mass/4,mass/2,mass/4)end car.Chassis.RotVelocity=car.Chassis.RotVelocity:Lerp(a,.1)else bodyVelocity.maxForce=Vector3.new(0,0,0)bodyAngularVelocity.maxTorque=Vector3.new(0,0,0)end for a,R in pairs(car:GetChildren())do if R.Name=="\084\104\114\117\115\116\101\114"then UpdateThruster(R)end end end for a,R in pairs(car:GetChildren())do if R:FindFirstChild("\066\111\100\121\084\104\114\117\115\116")then R.BodyThrust:Destroy()end end bodyVelocity:Destroy()bodyAngularVelocity:Destroy()camera.CameraType=R userInputService.ModalEnabled=false if mobileGui then mobileGui:Destroy()end script:Destroy()end)
--A simple function to check if the car is grounded
local function IsGrounded()
	local hit, position = Raycast.new(
		(car.Chassis.CFrame * CFrame.new(0, 0, (car.Chassis.Size.Z / 2) - 1)).p,
		car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0, -1, 0)) * (stats.Height.Value + 0.2)
	)
	if hit and hit.CanCollide then
		return true
	end
	return false
end

local oldCameraType = camera.CameraType
camera.CameraType = cameraType

spawn(function()
	while character.Humanoid.SeatPart == car.DriveSeat do
		game:GetService("RunService").RenderStepped:wait()

		--Broken gyro input
		--[[if userInputService.GyroscopeEnabled then
			local inputObject, cframe = userInputService:GetDeviceRotation()
			local up = cframe:vectorToWorldSpace(Vector3.new(0, 1, 0))
			local angle = (1 - up.Y) * (math.abs(up.X) / up.X)
			movement = Vector2.new(angle, movement.Y)
		end]]

		if IsGrounded() then
			if movement.Y ~= 0 then
				local velocity = car.Chassis.CFrame.lookVector * movement.Y * stats.Speed.Value
				car.Chassis.Velocity = car.Chassis.Velocity:Lerp(velocity, 0.1)
				bodyVelocity.maxForce = Vector3.new(0, 0, 0)
			else
				bodyVelocity.maxForce = Vector3.new(mass / 2, mass / 4, mass / 2)
			end
			local rotVelocity = car.Chassis.CFrame:vectorToWorldSpace(
				Vector3.new(movement.Y * stats.Speed.Value / 50, 0, -car.Chassis.RotVelocity.Y * 5 * movement.Y)
			)
			local speed = -car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity).unit.Z
			rotation = rotation + math.rad((-stats.Speed.Value / 5) * movement.Y)
			if math.abs(speed) > 0.1 then
				rotVelocity = rotVelocity
					+ car.Chassis.CFrame:vectorToWorldSpace(
						(Vector3.new(0, -movement.X * speed * stats.TurnSpeed.Value, 0))
					)
				bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
			else
				bodyAngularVelocity.maxTorque = Vector3.new(mass / 4, mass / 2, mass / 4)
			end
			car.Chassis.RotVelocity = car.Chassis.RotVelocity:Lerp(rotVelocity, 0.1)

			--bodyVelocity.maxForce = Vector3.new(mass / 3, mass / 6, mass / 3)
			--bodyAngularVelocity.maxTorque = Vector3.new(mass / 6, mass / 3, mass / 6)
		else
			bodyVelocity.maxForce = Vector3.new(0, 0, 0)
			bodyAngularVelocity.maxTorque = Vector3.new(0, 0, 0)
		end

		for i, part in pairs(car:GetChildren()) do
			if part.Name == "Thruster" then
				UpdateThruster(part)
			end
		end
	end
	for i, v in pairs(car:GetChildren()) do
		if v:FindFirstChild("BodyThrust") then
			v.BodyThrust:Destroy()
		end
	end
	bodyVelocity:Destroy()
	bodyAngularVelocity:Destroy()
	camera.CameraType = oldCameraType
	userInputService.ModalEnabled = false
	if mobileGui then
		mobileGui:Destroy()
	end
	script:Destroy()
end)
