Hello i am having a tough time creating some camera movements. I tried a couple different things and nothing really gave me the outcome i wanted. I’m hoping people here can help me out and guide me on how i can get my goal.
Below is a n image of what i want. I am on the forums now asking if anyone can help with figuring out how to create this kind of camera movement. Where the camera is the only thing rotating while player is standing still but it moves based on where the mouse is relative to center.
Here is an over-the-shoulder camera script that I wrote a few months ago. It’s isn’t exactly directly above the player’s head, but try playing around with the settings and you should be able to achieve what you want.
-- definitions
local RUNSERVICE = game:GetService("RunService")
local PLAYERS = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local CAMERA = workspace.CurrentCamera
local PLAYER = PLAYERS.LocalPlayer
local CHAR = PLAYER.Character or PLAYER.CharacterAdded:wait()
local ROOT = CHAR:WaitForChild('HumanoidRootPart')
-- setup
CAMERA.CameraType = Enum.CameraType.Scriptable
-- variables
local ZOOM = 10
local ZOOMlower = 8
local ZOOMupper = 16
local ZOOMincr = 2
local X = 0
local Y = 0
local RX = 0
local RY = 0
local PANSPEED = 10
local SKEW = 0.2 --skewed sensitivity
-- functions
function halflerp(a,b,alpha)
return a+(b-a)--*alpha
end
function PanCamera(dt)
UIS.MouseBehavior = "LockCenter"
local DELTA = UIS:GetMouseDelta()*SKEW
local ROOTCF = CFrame.new(ROOT.Position)
local OFFSET = CFrame.new(3,2,ZOOM)
local MODSPEED = PANSPEED*dt
--[[
X = X-DELTA.X
Y = Y-DELTA.Y
]]--
X = X-DELTA.X
Y = math.clamp(Y-DELTA.Y,-70,70)
RX = halflerp(RX,math.rad(X),MODSPEED)
RY = halflerp(RY,math.rad(Y),MODSPEED)
local absOFFSET = CFrame.Angles(0,RX,0)*CFrame.Angles(RY,0,0)*OFFSET
CAMERA.CFrame = CAMERA.CFrame:Lerp(ROOTCF*absOFFSET,MODSPEED)
end
function SetZoom(input,other)
if other then return end
if input.UserInputType == Enum.UserInputType.MouseWheel then
local dt = input.Position.Z
if dt > 0 then
ZOOM = math.clamp(ZOOM-ZOOMincr,ZOOMlower,ZOOMupper)
elseif dt < 0 then
ZOOM = math.clamp(ZOOM+ZOOMincr,ZOOMlower,ZOOMupper)
end
end
end
-- script
RUNSERVICE:BindToRenderStep('ShoulderCam',Enum.RenderPriority.Camera.Value - 1,PanCamera)
UIS.InputChanged:Connect(SetZoom)
This script uses GetMouseDelta() of the player’s mouse (which makes this incompatible with mobile and xbox) and then uses the returned values to pan the camera around the player’s HumanoidRootPart.
Put inside of StarterCharacterScripts or StarterGui so that it loads every time the player’s Character property loads.