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:
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:
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.
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
-- 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.