Custom Planetary Gravity Camera

I’ve created a custom planetary gravity script utilizing Roblox’s custom character controllers, however. I’m faced with an issue regarding the camera.


Above is how the camera turns out. I want it to rotate so that it angles itself alongside the character, like the mock-up version below:

Such that the camera and the player’s position relative to the planet stays consistent, and rotates alongside them.

I’ve tried searching around for how I could go about this, but could only find EgoMoose’s controller module, which was difficult to understand and apply the camera code of to my system.

have you tried updating the camera’s z rotation according to the hrp’s rotation like this?

local cam = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer

game:GetService('RunService').RenderStepped:Connect(function()
	local char = plr.Character or plr.CharacterAdded:Wait()
	local hrp = char:FindFirstChild("HumanoidRootPart") or char:WaitForChild('HumanoidRootPart') -- just in case if the hrp isn't present for some reason

	local _, _, z = hrp.CFrame:ToOrientation()

	cam.CFrame = cam.CFrame * CFrame.Angles(0, 0, z)
end)

Roblox’s camera doesn’t really support this; you could add the relative Z rotation of the humanoidrootpart’s cframe from the currentcamera to the currentcamera (local relativeRotation = workspace.CurrentCamera.CFrame.Rotation:ToObjectSpace(humanoidrootpart.CFrame.Rotation) and each frame add the Z value of relativeRotation to CurrentCamera, or something similar)

But even if you tweaked the values around until it works, when you go to rotate the camera as the player, it won’t move in the direction you expect it to; i.e. if your camera is sideways and you drag it to look up, your camera will end up turning left.

If this is a really important part of your game, I would recommend making a new camera system from scratch using properties like mouse.Delta

1 Like