How to align player against a wall depending on which surface the player is facing?
I'm making a climbing script that allows the player to climb certain walls in the game. I am trying to make the player orientation so it's facing the building. Example
Now here’s the reason why my question is awfully long, you can’t just have the player face towards the center of the building, this is incorrect, instead you need them to be aligned with the wall. The easiest way this can be done is through raycasting.
So using FindPartOnRayWithIgnoreList it is possible to get the surface direction easily.
02 | local characterDes = Char:GetDescendants() |
03 | for i, instance in pairs (characterDes) do |
04 | if instance.ClassName = = "Part" then |
05 | table.insert(ignoreList, instance) |
09 | local surfaceray = Ray.new(character.HumanoidRootPart.Position, character.HumanoidRootPart.Position+ [ CLIMBABLE_PART_HERE ] .Position) |
10 | local part, position, surface = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList) |
Okay now that you've caught up with me, how would I use this surface variable to CFrame my character through the use of BodyGyro? I can't really think of any efficient way to use this veriable. Could someone help me understand the maths behind orienting the player using this?