Need some help with making a good camera system for my hoverboard thingy, heres a video:
btw, i’m making a minigame based on hoverboards like TRON just for fun.
Here’s the code:
-- /) PUG64 (\ --
-- //Services
local RS = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
-- //Important Variables
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local Mouse = Player:GetMouse()
-- //Modules
-- //Contextual Variables
local OffsetCF = CFrame.new()
local IsDown = false
local Shiftlock = false
local X = 0
local Y = 0
local Zoom = 15
local InterpolerationAmount = 1
-- //Functions
local function GetObjectZoom(Dummy,Params)
local Character = Player.Character
local Unit = -(Player.Character.PrimaryPart.Position - (CFrame.new(Character.PrimaryPart.CFrame.Position) * CFrame.Angles(Dummy:ToEulerAnglesXYZ()) * CFrame.new(0,0,Zoom)).Position).Unit
local ray = workspace:Raycast(Character.PrimaryPart.Position,Unit * Zoom,Params)
if ray and ray.Instance.CanCollide then
return (ray.Position - Player.Character.PrimaryPart.Position).Magnitude - 0.2
else
return Zoom
end
end
-- //Main
Mouse.Button2Down:Connect(function()
IsDown = true
repeat task.wait() until not UIS:IsMouseButtonPressed(Enum.UserInputType.MouseButton2)
IsDown = false
end)
UIS.InputBegan:Connect(function(inp)
if inp.KeyCode == Enum.KeyCode.LeftControl then
Shiftlock = not Shiftlock
end
end)
UIS.InputChanged:Connect(function(inp)
if inp.UserInputType == Enum.UserInputType.MouseMovement then
X += inp.Delta.X
Y = math.clamp(Y + inp.Delta.Y,-140,140)
elseif inp.UserInputType == Enum.UserInputType.MouseWheel then
Zoom += inp.Position.Z * -4
Zoom = math.clamp(Zoom + inp.Position.Z * -4,1,100)
end
end)
RS.RenderStepped:Connect(function()
Camera.CameraType = Enum.CameraType.Scriptable
if IsDown and not Shiftlock then
UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
elseif Shiftlock then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
else
UIS.MouseBehavior = Enum.MouseBehavior.Default
end
local Character = Player.Character
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
if Character and not Shiftlock then
Character.Humanoid.AutoRotate = true
local Dummy = Camera.CFrame
Dummy = CFrame.new(Character.PrimaryPart.CFrame.Position) * CFrame.Angles(Y * -0.01,0,0)
Dummy *= CFrame.fromAxisAngle(Dummy:VectorToObjectSpace(Character.PrimaryPart.CFrame.UpVector),-X * 0.01)
local R = Zoom
local Position = (CFrame.new(Character.PrimaryPart.CFrame.Position) * CFrame.Angles(Dummy:ToEulerAnglesXYZ()) * CFrame.new(0,0,R)).Position
Camera.CFrame = CFrame.lookAt(Position,Character.PrimaryPart.Position)
end
end)
If someone is good at CFrames and that sort, please interact with the post.