How do I switch the directions on a rotated axis?

Right now I am stuck with a rotated axis which has the correct “up” direction, but the incorrect forward and right directions. I want to swap the forward and right directions but I have no idea on how to even start on that.

local normal = getSurfaceNormal()
local UP = Vector3.new(0, 1, 0)
local axis = UP:Cross(normal);
local theta = math.rad(45)
local vAxis = CFrame.fromAxisAngle(axis, theta)

My goal is to switch the blue and black arrows, whilst keeping the red arrow the same. Any ideas?
image

Goal:
image

I’m not sure but I think you can just offset theta by 90 degrees in a certain direction?

Offsetting theta by 90 degrees won’t switch the black and blue directions like I want, but rather rotate the axis on the black line by 90 degrees.

1 Like

try using

UP:Cross(-normal)

That only inverses the rotation that the object will rotate on in the blue axis, instead of switching the black and blue directions.

yep, but then apply the 90 degree offset.
so like:

local normal = getSurfaceNormal()
local UP = Vector3.new(0, 1, 0)
local axis = UP:Cross(-normal);
local theta = math.rad(45)
local vAxis = CFrame.fromAxisAngle(axis, theta + math.pi/2) -- might be - math.pi/2

also you can fix this problem easily by switching the usage of the variables axis and vAxis for whatever you are using it for. You should not have to change any math at all

SwagMasterAndrew already suggested doing that, which doesn’t switch the black and blue axes, but rather creates an offset of 90* on the blue axis and doesn’t affect the black axis at all

Why would you swap the arrows? You already have references to both of them, just use the correct one where needed, if you want to swap the arrows just draw the picture using different colors.

2 Likes

Ah nevermind! I found the solution. I was overthinking the problem. Thanks all

Oh nice, just wondering, how did you do it?

My thought was just to make the black arrow become equal to the blue arrow’s x/y/z numbers (vice-versa).

It’s impossible to produce the axis in the picture you are showing, if the blue line is the Z axis (LookVector) and the black one is the X axis (RightVector), then you cannot swap them and change the RightVector to LeftVector, if your main goal is to change the look vector and not the right vector then you could just rotate the axis by 90 degrees on any direction you want, Here is how it should look like in an image by the way image
For the code you could try this (I haven’t tested it)

local OriginalAxis = getSurfaceNormal() -- Just set this the the initial CFrame (Must be CFrame)
local Degrees = 90
local NewAxis = OriginalAxis * CFrame.Angles(0,math.rad(Degrees),0)
2 Likes