Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to rotate player with teleportation?

Asked by
mewtify 26
2 years ago

Hey, I can't figure out how to rotate a player. I'm trying to make sense of CFrames but I am having trouble with it. Here is my code

if hit.Parent:findFirstChild("Humanoid") then
    local telepoint = Vector3.new(224.152, 61.043, -519.523)
    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(telepoint + Vector3.new(0,3,0))
end

I want the player's orientation to be "0,-168,0" after they teleport, but I'm not sure how to do that since it all seems to have to do with adding and multiplying and stuff like that.

If there is an alternate way to do this without CFrames please let me know but I'm not sure what to do.

Thank you!

1 answer

Log in to vote
0
Answered by 2 years ago

Hiya!

The easiest way tow can rotate the player's HumanoidRootPart using CFrame.Angles() A quick run-down as to how you add CFrames and Vector3;

  • CFrame uses * (multiply) and / (divide)
  • Vector3 uses + (addition) and - (subtract)

To set the rotation with CFrame.Angles, you have your X, Y and Z variables, and to actually rotate, we need to use math.rad (radians) to get out -168 rotation

-- Assuming 'telepoint' is our desired vector
PlayerCFrame = CFrame.new(telepoint) * CFrame.Angles(0, -math.rad(168), 0)

Our full code would look like this:

if hit.Parent:FindFirstChild("Humanoid") then
    local telepoint = Vector3.new(-36.572, 0.5, -0.269) + Vector3.new(0,3,0)
    hit.Parent.HumanoidRootPart.CFrame = CFrame.new(telepoint) * CFrame.Angles(0, -math.rad(168), 0)
end

Hope this helps! ????

Ad

Answer this question