Im trying to create a Third-person shooter framework, im having issues with creating the camera system itself
Basically everytime I right click or press q, I want the camera to actually point in the direction its looking at, instead for some reason the camera just points to this exact direction everytime which is not how i intend for it to work.
Here is a video on how its working right now;
As you can see, the orientation values continue to change to the SAME values, no matter where i point my camera, I want them to point to the current orientation values that the camera is currently at.
I will provide the relevant parts of the code as to not confuse anybody with anything unrelated.
-- Values --
local Offset = Vector3.new(4,4,7)
local xAngle = 0
local yAngle = 0
local IsAiming = false
local isShooting = false
local Is_Reloading = false
Player:SetAttribute("Aiming", IsAiming)
local function PlayerInput(actionName, inputState, inputObject)
print("playerinput")
if inputState == Enum.UserInputState.Change then
xAngle -= inputObject.Delta.X
yAngle = math.clamp(yAngle - inputObject.Delta.Y * 0.4, -75, 75)
print("Player input: xAngle:", xAngle, "yAngle:", yAngle)
end
end
-- same script just another block of code
local function Client_Aim(Began)
print("aiming")
local Found_Gun = Find_Weapons()
if Found_Gun == nil then return end
if Began then
Humanoid.AutoRotate = false
if Character and HumanoidRootPart then
Player:SetAttribute("Aiming", true)
ContextActionService:BindAction("PlayerInput", PlayerInput, false, Enum.UserInputType.MouseMovement)
local x, y: number = workspace.CurrentCamera.CFrame:ToOrientation()
xAngle, yAngle = x, y --update
print(xAngle, yAngle)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
local StartRootCFrame = CFrame.new(HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, math.rad(xAngle), 0) * CFrame.Angles(math.rad(yAngle), 0, 0)
local CameraCFrame = StartRootCFrame:PointToWorldSpace(Offset)
local CameraFocus = StartRootCFrame:PointToWorldSpace(Vector3.new(Offset.X, Offset.Y, -100000))
CurrentCamera.CFrame = CFrame.lookAt(CameraCFrame, CameraFocus)
local LookingCFrame = CFrame.lookAt(HumanoidRootPart.Position, CurrentCamera.CFrame:PointToWorldSpace(Vector3.new(0,0,-100000)))
HumanoidRootPart.CFrame = CFrame.fromMatrix(HumanoidRootPart.Position, LookingCFrame.XVector, HumanoidRootPart.CFrame.YVector)
end)
end
end
if not Began then
Player:SetAttribute("Aiming", false)
Humanoid.AutoRotate = true
ContextActionService:UnbindAction("PlayerInput")
RunService:UnbindFromRenderStep("CameraUpdate")
end
end