Vector math question

I want to know how to “normalize” a direction based on a ray and the position that the ray hit.

sorry if my vocabulary is wrong I’m not very experienced in advanced vector math

I am attempting to make a wall running system, and for my math involved in calculating where the player should be next along the wall I have run into a problem that I believe can be solved with either dot product or cross product but I’m not sure specifically how to apply either of those.

I’ll explain how my wall running system works:

First, there is a ray that is created to detect if there is a wall to run on. This would be represented as a in this diagram:

Second, if a wall is found, I want to use the b direction to find where in relation to the wall that was hit that the player should start wall running at.

This would work because I could scale the B direction to be as far away from the wall as I wanted, and it would theoretically work anywhere along the curve, or anywhere on a flat surface.

My problem is that I can’t figure out how to get said b direction. I looked into cross product and dot product, and I saw in a post by sleitnick how to get a c direction:

But, I couldn’t figure out how to get b which would be inbetween both of these.

I’ve tried to use the Normal that is returned by the ray that is a, but I don’t believe that this will work in my scenario, unless I am applying the normal incorrectly. Any help is appreciated.

No problem, in order to calculate the middle vector (b) you could either:

  1. (easiest) - use the normal from a ray from the wall and plug it into something like wall.CFrame:VectorToObjectSpace(normal)

  2. (more complex) use this method

local angle = math.acos(a:Dot(c))
local b = CFrame.fromAxisAngle(Vector3.new(0, 1, 0), angle / 2):VectorToWorldSpace(a)

the second one is untested lol, so if it doesn’t work lemme know

I believe the Normal that is returned using raycasting is the normal relative to the brick. Maybe the normal would work for you if you converted it to world space?

hitPart.CFrame:VectorToWorldSpace(hitPartNormal)