Help With Aligning Part With Player

Hey Developers, I am struggling to get a portal to be aligned with the player when they spawn one in. Currently when they spawn one in it looks like this:
I want it so the rotation is changed and it looks like this:
but my issue is I am a rookie when it comes to CFrame and I cannot figure out how I can align this I’d really appreciate it if I can have some help and an in depth explanation so I can understand CFrame better. Here’s my code:

	local Character = player.Character or player.CharacterAdded:Wait()
	local portal = portalsAssigned[player.UserId]
	local portalClone = ServerStorage.Portals:FindFirstChild(portal):Clone()
	portalClone.Parent = workspace
	portalClone.CFrame = * 5 + Character.HumanoidRootPart.Position, Character.HumanoidRootPart.Position)
1 Like

The CFrame calculation is correctly done. Probably, the problem is that the portal is incorrectly orientated, in order for it to work, the face of the portal that you want to be looking at the player must be the frontal one; you can check this by creating a decal inside the portal and setting its Face property to Front.

Alternatively, you can change the portal’s pivot or manually rotate 90° in the script.

local PortalCF = CFrame.lookAt(Character.HumanoidRootPart.CFrame.LookVector * 5 + Character.HumanoidRootPart.Position, Character.HumanoidRootPart.Position)
local AdjustedCF = PortalCF * CFrame.Angles(0, math.pi/2, 0) -- math.pi/2 rad = 90 deg.

Thanks alot, I used the 90 Degrees change over and it works perfectly. I’m assuming I can also use Math.Rad(90) to also get 90 degrees in a CFrame script?

1 Like

Yep, you’re right. Dividing pi to get a number in radians is just a little bit faster than the math.rad() function.


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