Changing the direction of a vector based on direction of another

This is for a wall-run mechanic. I have a part representing the direction of a wall. I need to face backward if the player is going in the opposite direction of the wall. My method so far has been casting rays to each side of the player then using the normal to find the wall direction with Normal:Cross(,1,0)).
How would I go about making the direction from that face backward depending on the angle the player / casting part is at.

1 Like

You mean you are trying to find the direction between the wall and the player, is that it?

I thinkk you may be right, im trying to find the direction the player should move along the wall.

If I understand you correctly, you’re basically trying to project the LookVector of the HumanoidRootPart so that it’s parallel to the wall surface, and has a Y-component of 0?

I think you could just do

local normal = -- ... wall normal
local look = character.HumanoidRootPart.LookVector
local up = normal:Cross(look)
local dir = up:Cross(normal)

dir is then the vector. You can swap up and normal in the last line to reverse it


Yeah, what he said lmaooo, I had forgotten about LookVector, I was looking for that function. To clarify, normal would be:

local normal = wall.CFrame.UpVector

Of course if it really is the upvector or any other depends on if you have the part rotated completely upside down and things of the sort

I’m trying to figure out how to find out when to reverse it.

It will flip direction automatically. By “reverse” I meant if you want it to face in the same direction as the character, or the opposite.