Custom camera angles

The top clip is what i want, the second clip is what i have right now. In my version the camera seems glued to the right arm of the character whereas in the top clip its on the right side, this becomes a problem when the character is facing the screen, in the version i want the camera remains focused on the right side of the character whereas in my version it remains focused on the character’s right side.

RunService.Heartbeat:Connect(function()
    local currentCamera = workspace.CurrentCamera.CFrame
    currentCamera = char:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(2,0,0) * currentCamera.Rotation
end)

Please help I’ve been stuck on this for a while

char:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(2,0,0)

If my hunch is correct this piece of code adds 2 to the right of the root part in it’s local space which translates to that “attachment” to the right side of the root part.

You’ll have to change your approach by taking the camera’s viewing angle and then offsetting the camera’s position CFrame from the HumanoidRootPart depending on the camera viewing angle’s RightVector property.

I also came to that conclusion and this is my code now, I don’t even know why its not working now

The camera behavior you’re trying to replicate is identical to that of a spring. You can use Quenty’s Spring module to achieve the same effect, it’s very lightweight & straightforward to use.

Library link:
https://github.com/Quenty/NevermoreEngine/blob/main/src/spring/src/Shared/Spring.lua

Documentation:
https://quenty.github.io/NevermoreEngine/api/Spring/

I found about this implementation through this video which is very informative and also has code examples:
https://www.youtube.com/watch?v=Db3LooLQM1Q
(Skip to 23:10)

this seems perfect, how do I Import the module though (never used one off of github before)

Springs are used to smooth things out. They’re very useful and make camera movement’s smooth but don’t do alignment though.


Here is some code that should do what you’re looking for:

-- Goes in StarterCharacterScripts
local RunService = game:GetService("RunService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local hrp = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera

local function beforeCamera(delta)
	-- Code in here will run before the default Roblox camera script
	-- Offsets the camera 2 studs in the "right direction" of the camera
	local worldCameraOffset = camera.CFrame.RightVector * 2
    local characterCameraOffset = hrp.CFrame:VectorToObjectSpace(worldCameraOffset)
    humanoid.CameraOffset = characterCameraOffset
end

-- Bind the update to run before the camera update
local NAME = "Alignment before camera"
RunService:BindToRenderStep(NAME, Enum.RenderPriority.Camera.Value - 1, beforeCamera)
humanoid.Died:Once(function()
	-- Remove the binding when the character dies (could also be when a new character is added with player.CharacterAdded, getting the player from `character`)
	RunService:UnbindFromRenderStep(NAME)
	humanoid.CameraOffset = Vector3.new(0,0,0)
end)

Basically it sets the camera offset each frame to be 2 studs in the “right” direction of the camera’s orientation/CFrame.

1 Like

Oh my god its perfect tysm. Comments are super helpful as well I’m going to read up on all of this, seriously can’t thank you enough for your help, as with everyone else in this thread.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.