So, I’m making a shooter and I want to have a camera like how Helldivers 2 has theirs.
Here is my cade so far (not mine):
-- // Variables
-- # Services
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local playersService = game:GetService("Players")
-- # Objects
local player = playersService.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character.HumanoidRootPart
local humanoid = character.Humanoid
local camera = game.Workspace.CurrentCamera
-- // Functions
humanoid.CameraOffset = Vector3.new(0, 0, 0)
humanoid.AutoRotate = false
function RayCast(PositionA,PositionB,Params)
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = Params
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(PositionA, PositionB - PositionA, raycastParams)
if raycastResult then
return raycastResult
else
return nil
end
end
runService:BindToRenderStep("Shiftlock", Enum.RenderPriority.Character.Value, function()
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative
local cameraCFrame = camera.CFrame
local lookVector = -cameraCFrame.LookVector
local angle = math.atan2(lookVector.x, lookVector.z)
RayCast()
humanoidRootPart.CFrame = CFrame.new(humanoidRootPart.Position) * CFrame.Angles(0, angle, 0)
end)
In case you don’t know how helldivers camera is you can move around your character while still having your camera in a direction. when you aim, your character then turns to the direction your camera is looking.