You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
The player to correctly rotate with the camera -
What is the issue? Include screenshots / videos if possible!
The player’s character doesn’t rotate correctly.
Video of error:
https://gyazo.com/c01370a6c4d5bc5f3a3306a2154832a7
Camera Code:
local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera
local humanoid = script.Parent:WaitForChild("Humanoid")
local userInputService = game:GetService("UserInputService")
local offset = script.Parent.Settings.Offset
local direction = script.Parent.Settings.Direction
local offsetX = script.Parent.Settings.OffsetFactor
local rotation = script.Parent.Settings.RotationFactor
local offsetY = 0
local offsetZ = 0
local zoomedIn = false
local locked = true
local dead = false
local to
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.25)
local originalWaistC1 = script.Parent:WaitForChild("UpperTorso"):WaitForChild("Waist").C1
local function tween(object, goal)
end
userInputService.InputEnded:Connect(function(input, gameProcessed)
if input.KeyCode == Enum.KeyCode.V and not gameProcessed then
zoomedIn = not zoomedIn
elseif input.KeyCode == Enum.KeyCode.G and not gameProcessed then
locked = not locked
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
script.Parent.Settings.Locked.Value = locked
humanoid.WalkSpeed = script.Parent.Settings.Speed.Value
userInputService.MouseIconEnabled = not locked
player.PlayerGui.Crosshair.Crosshair.Visible = locked
if locked then
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
if script.Parent:FindFirstChildOfClass("Tool") then
UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative
else
UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.MovementRelative
end
else
if not dead then
userInputService.MouseBehavior = Enum.MouseBehavior.Default
UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.MovementRelative
else
userInputService.MouseIconEnabled = false
player.PlayerGui.Crosshair.Crosshair.Visible = false
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.MovementRelative
end
end
cam.CameraType = Enum.CameraType.Custom
cam.FieldOfView = script.Parent.Settings.FOV.Value
local leanOffset = offsetX.Value
if not dead then
if direction.Value > 0 and offset.Value < 0 and to ~= "R" then
to = "R"
local a = tweenService:Create(offset, tweenInfo, {Value = 1.75})
a:Play()
a.Completed:Connect(function(playbackState)
if playbackState ~= Enum.PlaybackState.Cancelled then
to = nil
end
end)
elseif direction.Value < 0 and offset.Value > 0 and to ~= "L" then
to = "L"
local a = tweenService:Create(offset, tweenInfo, {Value = -1.75})
a:Play()
a.Completed:Connect(function(playbackState)
if playbackState ~= Enum.PlaybackState.Cancelled then
to = nil
end
end)
end
script.Parent.UpperTorso.Waist.C1 = CFrame.Angles(0, 0, math.rad(-rotation.Value*0.8)) * originalWaistC1
if not zoomedIn then
local x = offset.Value + leanOffset/2
local y = offsetY
local z = offsetZ
workspace.CurrentCamera.CFrame *= CFrame.new(x,y,z)
--humanoid.CameraOffset = Vector3.new(offset.Value + leanOffset/2, offsetY, offsetZ)
else
local x = leanOffset*2
workspace.CurrentCamera.CFrame *= CFrame.new(x,0,0)
--humanoid.CameraOffset = Vector3.new(leanOffset*2, 0, 0)
end
cam.CFrame *= CFrame.Angles(0, 0, math.rad(rotation.Value))
if not zoomedIn then
player.CameraMode = Enum.CameraMode.Classic
else
player.CameraMode = Enum.CameraMode.LockFirstPerson
end
end
end)
script.Parent:WaitForChild("Fire").OnClientEvent:Connect(function(isHeadShot)
player.PlayerGui.Crosshair.Hitmarker.Visible = true
if isHeadShot then
player.PlayerGui.Crosshair.Hitmarker.ImageColor3 = Color3.fromRGB(255,0,0)
else
player.PlayerGui.Crosshair.Hitmarker.ImageColor3 = Color3.fromRGB(255,255,255)
end
wait(0.05)
player.PlayerGui.Crosshair.Hitmarker.Visible = false
end)
humanoid.Died:Connect(function()
locked = false
player.CameraMode = Enum.CameraMode.LockFirstPerson
dead = true
humanoid.CameraOffset = Vector3.new()
wait()
script:Destroy()
end)
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve tried to make my own rotation system (all it did was result in the player flinging around the map) and I’ve searched on the dev forum but I couldn’t find anything. Any forms of help would be greatly appreciated!