Hi! I want to have the player look in the same direction as a part, whilst still maintaining their position and UpVector. I want the player to be looking in the same direction as a part not looking at the part. I tried a lot of things, putting in a lot of numbers but I can never get it to work. I’ve tried using CFrame.LookAt and it’s just not working. What’s an easy or good way to position this?
I want the player to be like this in relation to the part.
I’m doing this in a wall jump which changes the humanoid root parts velocity to spring towards the other side which all works fine, but the player is never position correctly in relation to the part.
However, this doesn’t work properly, if the said part is backwards for whatever reason. In this case, you would try to use the negative position instead.
Okay that doesn’t really work. What I mean is I want the UpVector to be the same but it’s not working in lookAt I think? I’m not very good with CFrame.
The only step remaining is to ensure that the CFrame.fromOrientation(0, HumanoidRootPart.Orientation.Y, HumanoidRootPart.Orientation.Z). Pretty sure it works?
It is still confusing how this should be aligned. Because I’m lacking sufficient information to actually visualize this correctly as you put it.
Some vector math and CFrame.fromMatrix will work for this:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local part = workspace.Part -- or whatever
game:GetService("RunService").Stepped:Connect(function(t, dt)
local up = root.CFrame.UpVector -- could also set this to a constant Vector3.new(0,1,0)
local almostBack = (root.Position - part.Position).Unit
local right = up:Cross(almostBack)
root.CFrame = CFrame.fromMatrix(root.Position, right, up)
end)