Hi, so I ran into this problem where I have to teleport my character to the desired Vector3, to play an animation, but the problem is… my character is not facing the model which means I can’t play the animation in the right direction.
Rotate the humanoid root part to face the look vector of the part you are teleporting too. Make sure that part’s front face is correctly facing where the player should be orientated.
function lookAt(chr,target) --assume chr is a character and target is a brick to look towards
if chr.PrimaryPart then --just make sure the character's HRP has loaded
local chrPos=chr.PrimaryPart.Position --get the position of the HRP
local tPos=target.Position --get the position of the target
local newCF=CFrame.new(chrPos,tPos) --create our CFrame
chr:SetPrimaryPartCFrame(newCF) --set the HRP's CFrame to our result, thus moving the character!
end
end
local ClickDetector = game.Workspace.Map.Vent.VentBase.ClickDetector
ClickDetector.MouseClick:Connect(function()
local chr = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local target = game.Workspace.Target
function lookAt(chr,target) --assume chr is a character and target is a brick to look towards
if chr.PrimaryPart then --just make sure the character's HRP has loaded
local chrPos=chr.PrimaryPart.Position --get the position of the HRP
local tPos=target.Position --get the position of the target
local newCF=CFrame.new(chrPos,tPos) --create our CFrame
chr:SetPrimaryPartCFrame(newCF) --set the HRP's CFrame to our result, thus moving the character!
end
end
lookAt()
--player.Character:moveTo(Vector3.new(-42, 3, -27.61))
game:GetService("ContextActionService"):BindActionAtPriority(
"t",
function()
return Enum.ContextActionResult.Sink
end,
false,
Enum.ContextActionPriority.High.Value + 1,
unpack(Enum.PlayerActions:GetEnumItems())
)
--game.ReplicatedStorage.RemoteEvent:FireServer(player)
end)
game.ReplicatedStorage.RemoteEvent2.OnClientEvent:Connect(function(isnotMoving)
if isnotMoving == false then
game:GetService("ContextActionService"):UnbindAction("t")
end
end)