How to make a cframe value relative to the player's cframe/position?

I am using camera effects with cframe values (Moon Animator Import) but how can I make the cframe values relative to the player’s cframe with math?
When I print one of the CFrame’s Value it gives me:


while the player’s cframe is far away. So trying to play the camera animation would make me stare into space, any fixes?

Huh? Do you mean teleporting the player

No, changing the cframe value to be relative to the player, This is what I am going for
https://gyazo.com/fe8e6860487e67429fe09682eefacd85

local cam = --location
local plr = game.Players.LocalPlayer
local location = plr.Character.HumanoidRootPart.CFrame

cam.CFrame = location * CFrame.new(0, 6, 0)

Maybe this will work

1 Like

I am not sure if i did something wrong, but this is what happened.
https://gyazo.com/c5c7ac7a628453ac6611700efdf2e4af
Here is the code

local runservice = game:GetService("RunService")
local fold = game:GetService("ReplicatedStorage"):WaitForChild("Rush_Camera"):WaitForChild("Frames"):GetChildren()
local frames = #fold
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
for i=1,frames do
	local cf = fold[i]
	if cf then
		local val = cf.Value
		cf.Value = cf.Value * char.PrimaryPart.CFrame * CFrame.new(0,6,0)
		cam.CFrame = cf.Value
		runservice.RenderStepped:wait()
	end
end

I’m assuming you’re trying to make a cutscene type thing? If so why don’t you just use tweenService and do something like this:

-- This is a local script in StarterGui
-- LocationPart is a Part in Workspace.

wait(5); -- Just to make sure everything loads cause im lazy to check if the character actually loaded ;d
-- Services --
local PS = game:GetService("Players");
local WS = game:GetService("Workspace");
local TS = game:GetService("TweenService");

-- Variables --
local LocationPart = WS.LocationPart;
local CurrentCamera = WS.CurrentCamera;

local Player = PS.LocalPlayer;
local Character = Player.Character;
local RootPart = Character:WaitForChild("HumanoidRootPart");

-- Logic --
CurrentCamera.CameraType = Enum.CameraType.Scriptable; -- Set cam to scriptable for tween
TS:Create(CurrentCamera, TweenInfo.new(5), {CFrame = LocationPart.CFrame}):Play(); -- Tweens camera to the location part in workspace. Note you can edit the easing style, etc in tweenInfo

wait(10);
CurrentCamera.CameraType = Enum.CameraType.Custom; -- Basically reverts so the camera is focused on the CameraSubject (which should be the players humanoid)

Note that tween service is very customizable and you can edit the speed, easing style, etc in tweeninfo. See the below API for examples:

1 Like

The reason for the CFrame Values is because the camera animation was made in Moon Animator, and I want to play the moon animator camera animation, but make the cframe value relative to the player so you actually see the player during it.

I haven’t really used moon animator so I’m not to sure how it works. However, you could still do the exact same effect via tweenservice by setting the CurrentCamera’s CFrame to the players character BUT slightly behind or above (so the players visible) and tween the Camera from that position to the target point.

1 Like

Is it okay if you could provide an example? I’m not really getting it here.

Well, I’m assuming you want to do something like the below:

Using a already existing part and basically tweening the Camera from a starting part to an end target part (the green brick is the starting part, red brick is the end part):
https://gyazo.com/ed5b840c5e5e6e568ffc2ef26c01890a

Using the players RootParts current CFrame but offsetting by a bit:
https://gyazo.com/7e86e122a6a1e79a308f1b7bb2f11aca

-- This is a local script in StarterGui
-- StartLocation2 is a Parts CFrame in Workspace.
-- EndLocation is a Parts CFrame in Workspace.

wait(5); -- Just to make sure everything loads cause im lazy to check if the character actually loaded ;d
-- Services --
local PS = game:GetService("Players");
local WS = game:GetService("Workspace");
local TS = game:GetService("TweenService");

-- Variables --
local CurrentCamera = WS.CurrentCamera;

local Player = PS.LocalPlayer;
local Character = Player.Character;
local RootPart = Character:WaitForChild("HumanoidRootPart");

-- Locations CFrames
local Offset = Vector3.new(0, 0, 10); -- Humanoid rootpart offset

-- EXAMPLES --
local StartLocation1 = RootPart.CFrame*CFrame.new(Offset); --The start location is from the players rootpart but offset by a bit
local StartLocation2 = WS.StartLocation.CFrame; -- The start location is from a existing part in workspace

--
local EndLocation = WS.EndLocation.CFrame;

-- Logic --
CurrentCamera.CameraType = Enum.CameraType.Scriptable; -- Set cam to scriptable for tween
CurrentCamera.CFrame = StartLocation1; -- You can change it to StartLocation2 to see how it looks with 2 preset CFrames (using parts)
TS:Create(CurrentCamera, TweenInfo.new(5), {CFrame = EndLocation}):Play(); -- Tweens camera to the location part in workspace. Note you can edit the easing style, etc in tweenInfo

wait(10);
CurrentCamera.CameraType = Enum.CameraType.Custom; -- Basically reverts so the camera is focused on the CameraSubject (which should be the players humanoid)

They give similar results. If your cutscene is triggered by a specific event, then personally I would probably use 2 set CFrame locations (one being the start point, one being the end) → Setting the Camera to the start point (like I did in the above example) → CFraming the character to a specific location for the cutscene (so it looks more natural then using an awkward position the player might be in) → Tween the Camera to the end point CFrame.