How to get direction player is facing

Hello again, DevForums! Continuing from a post before that had fruitless results, I wanted to fix an issue with my wall climbing system where my horizontal controls would be inverted on the opposite side of the wall. I decided that it can be fixed if I can detect which direction the player is looking at in order to change the body velocity, and as a result, I am wondering if it is still possible to get the direction the player is facing in.

2 Likes

For clarification, you want the direction that the physical character is facing, or the camera?

You can just do HumanoidRootPart.CFrame.LookVector

1 Like

Sorry I wasn’t clear about that. I would want it to be based on where the character is facing and not where the camera is facing.

Assuming you are referring to the physical character’s look direction, you could use HumanoidRootPart.CFrame.LookVector (like @rottendogDkR mentioned).

That will return the Vector3 position of the front of the HumanoidRootPart. If you’re trying to detect whether the player is facing a certian object or such, you could use a Ray from the Vector3 position returned and forward.

6 Likes

Apologies, would like to revise that a bit. To get the exact CFrame of the facing direction, you would do the following:

direction = HumanoidRootPart.CFrame + HumanoidRootPart.CFrame.LookVector

From there, you could make a Ray from that CFrame value (direction) and continue from there.

1 Like

Thank you so much for both of your help! I was able to get the players to move along the walls correctly now with both of your help!

You should probably close this discussion since you have gotten a solution.

2 Likes