I want to be able to make the player teleport behind an object while keeping the initial facing direction towards the object the same and coming out the opposite side. (Like shown in image)
local a=CFrame.LookAt(p.CFrame,o.CFrame) -- p:GetPivot() instead of p.CFrame if p is a character
a+=a.LookVector*5+o.Position
p.CFrame=a -- or p:PivotTo(a) if character
maybe its the code you mean, use the following if p is a character:
local a=CFrame.LookAt(p:GetPivot(),o.CFrame)
a+=a.LookVector*5+o.Position
p:PivotTo(a)
Didn’t work, LookAt wouldn’t allow me to use the CFrame of p and o, so I used the position instead. PivotTo didn’t work because a is a vector3 instead of CFrame
I managed to get it working, here is the code for those who are interested:
local p = HRP
local o = workspace.TESTTP
local facingdirection = CFrame.lookAt(p.Position,o.Position)
--Position the character behind object
p.CFrame = CFrame.new(facingdirection.LookVector*5 + o.Position)
--Rotate the character so the back faces the object
p.CFrame = CFrame.lookAt(p.Position, o.Position) * CFrame.Angles(0, math.rad(180), 0)