How to flip the orientation of my CFrame

I have this CFrame that is used to teleport a player to a specific block when they die, however, when they are teleported to the block, the are facing backwards to the direction I want them to be facing. How would I fix this?

char:SetPrimaryPartCFrame(CFrame.new(TempCheckpoint.Position + Vector3.new(0, 3, 0)) * CFrame.Angles(0, TempCheckpoint.Orientation.Y + 90, 0))

.

1 Like

Instead of adding 90 to TempCheckpoint.Orientation.Y, you should subtract it by 90. This should face the player in the opposite direction that you’re experiencing at the moment.

1 Like

that did not work for some reason, it still has me spawning facing the wring direction!

1 Like

To turn an object backwards relative to its orientation, I usually just multiply the object’s CFrame by CFrame.Angles(0, math.pi, 0)

1 Like

so where in my code above would I insert that?

You could put an extra line after the one above like so:

char.PrimaryPart.CFrame = char.PrimaryPart.CFrame * CFrame.Angles(0, math.pi, 0)

i tried adding that line below and nothing really changed…

Like i always face a specific direction in the world, its like, always North, nomatter what I do

That’s interesting… Let’s try replacing the entire line with this one line:
char:SetPrimaryPartCFrame(CFrame.new(TempCheckpoint.Position + Vector3.new(0, 3, 0)) * CFrame.Angles(0, TempCheckpoint.Orientation.Y + 90, 0) * CFrame.Angles(0, math.pi, 0))

If this doesn’t work, then it sounds like something physics-related is causing the player to forcibly turn in that direction. Out of curiosity, would it be possible to rotate the TempCheckpoint so that it’s facing the opposite direction, causing the player to face the way you want?

1 Like

ok, so I rotated the brick, and used that code, and now it mostly works. The new issue is that the camera didnt swap, so you teleport looking at your self in third person. Do you happen have any idea how to fix that?

If you want to make it to where every time the player is teleported their camera is facing forward, you’ll need to add another script on the Client side as the player’s camera can’t really be manipulated by the Server.

I would create a RemoteEvent and put it in ReplicatedStorage. Name it ReadjustCamera.

Next, I would insert a LocalScript into the StarterGui with the following:

local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("ReadjustCamera") -- The name of the remote event

Remote.OnClientEvent:Connect(function()
	local camera = workspace.CurrentCamera
	local char = game.Players.LocalPlayer.Character
	
	camera.CFrame = char.Head.CFrame
end)

Then, after the code that teleports above, enter this: (player is the name of the PlayerObject. I assume since you have a char, you have a player to pass through the remote like below)

game.ReplicatedStorage.ReadjustCamera:FireClient(player)
1 Like

CFrames are using radians. Use CFrame.Angles(0, math.rad(TempCheckpoint.Orientation.Y + 90), 0)

These CFrame operations use radians, so that number 90 might be throwing everything off, even the solutions other people have suggested.

2 Likes

math.rad(TempCheckpoint.Orientation.Y + 90) if you want to convert an angle in degrees to radians (just adding to what you stated).

1 Like

I marked this as the solution because it got it mostly working, it is still finicky with the rotation being off for some orientations, but I will see if I can figure that out

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Head = Character:WaitForChild("Head")
local Camera = workspace.CurrentCamera

local RS = game:GetService("ReplicatedStorage")
local Remote = RS:WaitForChild("ReadjustCamera")

Remote.OnClientEvent:Connect(function()
	Camera.CFrame = Head.CFrame
end)

Change it to this though, to avoid redeclaring the same constants (variables with unchanging values) each time the event is fired and the connected callback function is subsequently executed.