-- / Client.lua / --


CarStartupSound:Play();
delay(.5, function()
	CarEngine:Play();
end)

for key in pairs(carSettings) do
	ContextActionService:BindAction(key, Control, false, Enum.KeyCode[key])
end

local accelerating = false;
local a = 0;
Heartbeat:Connect(function(dt)
	accelerating = false
	for key, property in pairs(carSettings) do
		if not property[1] then continue end;
		accelerating = true;
		
		if typeof(property[2]) == "Vector3" then
			BodyPosition.Position += property[2]*dt*a;
		elseif typeof(property[2]) == "number" then
			BodyGyro.CFrame *= CFrame.Angles(0, property[2]*dt*(a*.1), 0);
		elseif typeof(property[2]) == "CFrame" then
			BodyPosition.Position += Vector3.new(
				-math.sin(math.rad(CarModel.Orientation.Y))*property[2].X*dt*a,
				0,
				-math.cos(math.rad(CarModel.Orientation.Y))*property[2].X*dt*a
			) -- trig is evil
		end
	end
	
	if accelerating then
		a = math.clamp(a + accelerationSettings.inc*dt, 0, accelerationSettings.max);
		TweenService:Create(CarEngine, TweenInfo.new(dt), {PlaybackSpeed =  1 + (1*a/accelerationSettings.max)}):Play();
	else
		a = 0;
		TweenService:Create(CarEngine, TweenInfo.new(1), {PlaybackSpeed =  1}):Play();
	end
	
	
	
	accelerating = false;
end)
