Hey, everyone.
I’ve been trying to make a first person camera for my fps game, but, when adding crouching, I’ve run into some problems. I want to change the camera’s CFrame but in order to do that, I have to change the camera type to scriptable. Once I do that, the first person behavior goes away.
To attempt to fix this problem, I’ve tried multiple things. What got me the farthest was setting up a renderStepped event when the player crouches.
The problem with this solution is that the camera keeps rotating on its own.
Here’s a video demonstration:
robloxapp-20210906-0848578.wmv (2.7 MB)
Here are scripts related to the problem:
Local script:
game:GetService("RunService").RenderStepped:Connect(function(dt)
gunModule.update(viewmodel, dt, recoilSpring, bobbleSpring, swayingSpring, gunModel, isAiming)
player.CameraMode = Enum.CameraMode.LockFirstPerson
UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative
game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
end)
Module script:
local loop
function module.crouch(viewmodel, gun, isCrouching, isSprinting)
workspace.Camera.CameraType = Enum.CameraType.Scriptable --This is the problem. The camera mode can't be scriptable
local crouch = viewmodel.AnimationController:LoadAnimation(game.ReplicatedStorage.Animations.Crouch)
local hold = viewmodel.AnimationController:LoadAnimation(gun.GunAnims.Hold)
if isCrouching and not isSprinting then
TweenService:Create(workspace.Camera, TweenInfo.new(0.5, Enum.EasingStyle.Linear), {CFrame = workspace.Camera.CFrame * CFrame.new(0, -2, 0)}):Play()
task.wait(0.5)
loop = game:GetService("RunService").Heartbeat:Connect(function()
workspace.Camera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame * CFrame.new(0, -2, 0)
end)
elseif not isCrouching then
loop:Disconnect()
TweenService:Create(workspace.Camera, TweenInfo.new(0.5, Enum.EasingStyle.Linear), {CFrame = workspace.Camera.CFrame * CFrame.new(0, 2, 0)}):Play()
task.wait(0.5)
workspace.Camera.CameraType = Enum.CameraType.Custom
end
end
return module
Does anyone know a way that I can get rid of this rotating?