How to mirror a normal?

How would I get either the blue or green Vector3s?
Also case* not cause lol

In 3D the cross product between the normal vector and any other vector that isn’t pointing in the exact same or exact opposite direction will give a vector that’s 90 degrees from the normal, but it could be pointing in any direction around it, so without knowing what you’re trying to achieve it’s hard to say.

I want to add a force to the player that is parallel with a slope in 3D.

1 Like

Cool, the way I’d do that would be something like the following in GDScript, assuming you have the normal already.

var tangent = normal.cross(Vector3.DOWN)
var slope = normal.cross(tangent)
if slope.y < 0:
    slope = -slope

This gets a vector that is 90 degrees from the down direction and from the normal, which means it’s going to be going along the surface. Then to get the vector for the slope, you take the cross product the normal vector with the new vector, and it’ll be pointing up or down the slope. Then the if statement’s just there to make sure it’s pointing in the right direction up or down.

I hope I understood what you’re after, and that this helps.

This would work for different angles or slopes correct?

Oops, forgot to say, it won’t work if the normal is directly up (or down), so you’ll want to add a check for that. Aside from that, yeah, it should get you the direction for any normal.

1 Like

Sorry to bother you, it works, but I’m curious what is the if statement’s goal is?

No worries! So basically, there are two vectors at 90 degrees to the normal and down, pointing in opposite directions depending on which order you do the cross product in, and the same for when you . So the slope variable at the end could be pointing up the slope or down the slope based on what we’ve calculated. The if statement is there to check if it’s going down the slope, and flipping it if it’s the wrong way so the vector points up the slope.

I’m not great at visualizing chained cross-products to make sure the result is facing the right way, so putting an if-statement there is an easy way to make sure the vector is in the right direction, pointing up the slope instead of down the slope. It might be that you don’t need it, though.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.