Need ideas on wallrun alignment

I’ve been scripting for more than 5 years, but I’m really bad at math, CFrames. Thus I’ve never tried to make a walrun script.
My first attempt in making wallrun is using linear velocities or alignposition, they are all based on the hrp’s lookvector which works however, I want the player’s orientation to be aligned with the wall, how could I achieve this formula? (My goal is getting the LookVector goal of the result of comparing the character and the wall the character is running on, how will I achieve the perfect alignment so they won’t stray away or go the wrong angle since the advancement of my wallrun is based on lookvector)

I am trying to make my script work for any type of walls. You don’t need to worry about my script because it is basically just
LinearVelocity.VectorVelocity = hrp.CFrame.LookVector * speed

for those who think “TLDR” My goal is to align the character to face forward against any type of wall, my wallrun script is based on rootpart.CFrame.LookVector so once it accidentally strays away at an angle it goes further and further away from the wall

Here are examples of my problem:


the problem; loses speed or gets stuck because the character is looking more into the wall

This is my goal:

Think of the part as the character, it is getting aligned perfectly to the wall when i drag it to it. How do I achieve that formula?

1 Like

To get the desired look vector you use Vector3:Cross() But before you do that you have to get the surface normal of the wall you’re walking on. The way you do that is to fire a raycast from the character to the wall and then if the cast is successful, the result will have a property called normal which is what you need. So once you have the surface normal you get the lookvector like so:

local lookvector = normal:Cross(upvector)

if you want to learn more about the cross product, here is a guide that helped me

i didn’t make it very clear but the upvector you use to find the cross product is the upvector of the character

Thank you, I’ve read the resources… I learned something new, however… I don’t think this can solve my problem. But I’ve found a better way to explain what I want to happen, in this video i’m going to send. Think of the part as the character, perfectly aligning to the wall, how do I achieve that?


Though I think you understood my intention, it doesn’t get me close to finding the formula, I even asked chatgpt how to align it and it gave me the wrong formula.

Alright then, you’ll still need to do the steps i mentioned above but you’ll have to implement CFrame.fromMatrix.
This function takes a Position, LookVector, UpVector and a RightVector and turns it into a cframe.
the LookVector in this case will be equal to the one i showed above.
The UpVector will be equal to the surface normal
And the RightVector will be negative the upvector of the character. here is a forum which deals with a very similar issue and helped me to understand the fromMatrix function

A small mistake i made:
If the wall is in the right of the character, the RightVector will be negative the character’s UpVector, but if its on the right its positive.

Alright thanks, that looks like something that can help, I’ll get back to you once I try to get something done.