-- // Copyright 2023, vracto, All rights reserved.


local hum = script.Parent:WaitForChild("Humanoid")
local seat = nil

hum.Seated:Connect(function(active, seatPart)
	seat = seatPart
end)

local w = false
local s = false
local a = false
local d = false

game:GetService("UserInputService").InputBegan:Connect(function(inp, processed)
	if processed then return end
	if inp.KeyCode == Enum.KeyCode.W then w = true end
	if inp.KeyCode == Enum.KeyCode.S then s = true end
	if inp.KeyCode == Enum.KeyCode.A then a = true end
	if inp.KeyCode == Enum.KeyCode.D then d = true end
end)

game:GetService("UserInputService").InputEnded:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.W then w = false end
	if inp.KeyCode == Enum.KeyCode.S then s = false end
	if inp.KeyCode == Enum.KeyCode.A then a = false end
	if inp.KeyCode == Enum.KeyCode.D then d = false end
end)

local camera = workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local aa = 0

game:GetService("RunService").RenderStepped:Connect(function()
	if seat then
		print(a)
		print(d)
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = seat.Parent.Camera.CFrame * CFrame.Angles(math.rad((((mouse.Y - mouse.ViewSizeY / 2) / mouse.ViewSizeY)) * -20),math.rad((((mouse.X - mouse.ViewSizeX / 2) / mouse.ViewSizeX)) * -20),0)
		--seat.BodyGyro.CFrame = CFrame.new(seat.Parent.Body.Position, mouse.Hit.LookVector * 666)
		seat.BodyGyro.CFrame = CFrame.new(seat.Position, Vector3.new(mouse.Hit.X,mouse.Hit.Y,mouse.Hit.Z)) * CFrame.Angles(0, 0, math.rad(aa))
		if w then
			seat.BodyVelocity.Velocity = seat.CFrame.LookVector * 100
		elseif s then
			seat.BodyVelocity.Velocity = seat.CFrame.LookVector * -100
		else
			seat.BodyVelocity.Velocity = Vector3.new(0, 0, 0)
		end
		if a then
			aa+=3
		elseif d then
			aa+=-3
		else
			seat.BodyAngularVelocity.AngularVelocity = Vector3.new(0,0,0)
		end
	else 
		camera.CameraType = Enum.CameraType.Custom
	end
end)
