local function v()local v,C=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 v and v.CanCollide then return true end return false end local C=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 v()then if movement.Y~=0 then local v=(car.Chassis.CFrame.lookVector*movement.Y)*stats.Speed.Value car.Chassis.Velocity=car.Chassis.Velocity:Lerp(v,.1)bodyVelocity.maxForce=Vector3.new(0,0,0)else bodyVelocity.maxForce=Vector3.new(mass/2,mass/4,mass/2)end local v=car.Chassis.CFrame:vectorToWorldSpace(Vector3.new((movement.Y*stats.Speed.Value)/50,0,(-car.Chassis.RotVelocity.Y*5)*movement.Y))local C=-(car.Chassis.CFrame:vectorToObjectSpace(car.Chassis.Velocity)).unit.Z rotation=rotation+math.rad((-stats.Speed.Value/5)*movement.Y)if math.abs(C)>.1 then v=v+car.Chassis.CFrame:vectorToWorldSpace(Vector3.new(0,(-movement.X*C)*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(v,.1)else bodyVelocity.maxForce=Vector3.new(0,0,0)bodyAngularVelocity.maxTorque=Vector3.new(0,0,0)end for v,C in pairs(car:GetChildren())do if C.Name=="\084\104\114\117\115\116\101\114"then UpdateThruster(C)end end end for v,C in pairs(car:GetChildren())do if C:FindFirstChild("\066\111\100\121\084\104\114\117\115\116")then C.BodyThrust:Destroy()end end bodyVelocity:Destroy()bodyAngularVelocity:Destroy()camera.CameraType=C userInputService.ModalEnabled=false if mobileGui then mobileGui:Destroy()end script:Destroy()end)

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)
