How can I get the rotation of the player's character?

Hello everyone. Hope you are doing well. :slight_smile:

So I basically want to get the rotation that the character is facing relative to the world space, for example if he is facing one side that would be known as angle and the opposite facing side would be -angle. For example, if my player’s character is facing North, then the negative angle would be South and I want that angle in degrees if you get what I mean. I know you can use lookVector but I really need the angle that the character is facing in the world.

Thanks!

2 Likes

You can use Position:Angle(Position)

3 Likes

So like HRP.Position:Angle(HRP.Position)?

Thanks so much for helping me btw. :slight_smile:

1 Like

I had no idea this was a thing

1 Like
task.wait(3)

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")


local function getRotationAngle()
	local root = character:WaitForChild("HumanoidRootPart")
	local lookVector = root.CFrame.lookVector
	local angle = math.deg(math.atan2(lookVector.x, -lookVector.z))
	return angle
end

local rotationAngle = getRotationAngle()
print(rotationAngle)

used HumanoidRootPart here to avoid type errors.

2 Likes

HRP.Position:Angle(Vector3.new(0, 0, 0)) because you’re trying to get the angle relative to the world space which would be position 0,0,0 right? Idk try it out

Learn something new every day :smile:

1 Like

That stuff looks pretty cool …

Thanks, but it doesn’t seem to be working for me, the output just says 0. Thanks for your help so far. :slight_smile:

1 Like

Could you send your code?

Wouldn’t it just be HumanoidRootPart.Orientation.Y?

Since humanoid root part is a Base part, it has an orientation value, in angles, for all 3 axes

All you need would hypothetically be

Local plr = --path to player
Local char = plr.Character or plr.CharacterAdded:wait()
Local HRP = char:WaitForChild("HumanoidRootPart")

Local RotationY = HRP.Orientation.Y 

Correct me if I’m wrong
Sent from phone so bad capitalization

Hope I helped!

1 Like
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

local directionToCenter = (Vector3.new(0, 0, 0) - character:GetPivot().Position).Unit
local directionAngle = math.deg(character:GetPivot().LookVector:Angle(directionToCenter))
print(directionAngle)

In the code above, the center is position 0, 0, 0 in the game. Playtest and copy paste it into the console and spin your character around.

If the player is facing 0,0,0 the angle should be smaller than if the player is looking away from the center

I don’t think it’s working for me, because it is showing different numbers for opposite movement, but I might be wrong and it works and I just can’t detect that it does. Thanks so much for your help!