Hello everyone,
I recently stumbled upon a fantastic script that perfectly fits my game’s requirements. The script adds a delay to the camera movement, creating a smoother and more immersive experience. This reminded me of a game called “The Strongest Battlegrounds,” which had an impressive camera-to-head position attachment.
Motivated by this, I attempted to incorporate a similar feature into my own game. I successfully implemented it; however, I encountered an issue. Parenting the camera to an object other than the humanoid disrupts the shift lock functionality, which happens to be a critical aspect of my game.
Here’s what it looks with script disabled:
Here’s what it looks with script enabled:
Here’s the script I’m referring to:
--//Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
--//The Camera.
local Camera = workspace.CurrentCamera
--//Player Assets
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Head = Character:WaitForChild("Head")
--//Camera Block - Creates the CameraBlock responsible for making the "drag effect".
local CameraBlock = Instance.new("Part", Character)
CameraBlock.Size = Vector3.new(1, 1, 1)
CameraBlock.Name = "CameraBlock"
CameraBlock.CastShadow = false
CameraBlock.CanQuery = false
CameraBlock.CanTouch = false
CameraBlock.CanCollide = false
CameraBlock.Transparency = 0
--//Body Position - Responsible for positioning the CameraBlock to the Player's RootPart.
local BodyPosition = Instance.new("BodyPosition", CameraBlock)
BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
--//Main Loop
local function Loop()
--//Body Position - Sets the position of the BodyPosition.
BodyPosition.Position = Head.CFrame.Position + Vector3.new(0, (Humanoid.HipHeight - script:GetAttribute("CameraHeight")), 0)
--//Camera Stiffness - Controls the Stiffness of the movement.
BodyPosition.P = 1000 * script:GetAttribute("CameraStiffness")
--//Camera Subject - Sets the CameraSubject every frame to be our beautiful CameraBlock.
Camera.CameraSubject = CameraBlock
--//You can drag this one out of the loop, but other scripts will set the Subject to different instances instead of CameraBlock.
end
RunService:BindToRenderStep("Smooth Camera", 201, Loop)
Any help would be greatly appreciated!