Hello,
I similarly had a situation in which I had to figure out how to solve this problem, and it becomes quite simple, really. Assuming your the Vector3 of your thumbstick is accurate, here’s how to solve this problem:
First, you want to get the lookVector of the camera and ignore its Y value, and then get the unit of that. This is to remove any vertical rotation which might alter the direction of the camera.
Then, you want to solve for the angle between the cameraLookXZ vector and the thumbstick vector in 2d space. This can be done as follows:
Then, you want to convert the angle into a new unit vector.
After doing all of this, I got a function that looks as follows:
local function staticUnitToObjectSpace(staticV3, objectV3)
-- Remove vertical rotation of vectors
local objectUnitXZ = (objectV3 * Vector3.new(1,0,1)).unit
local staticUnitXZ = (staticV3 * Vector3.new(1,0,1)).unit
-- Calculate angle between vectors in 2D space
local theta = math.atan2(-staticV3.Z, -staticV3.X) - math.atan2(-objectUnitXZ.Z, -objectUnitXZ.X)
-- Convert angle to new unit vector
local newVector = Vector3.new(math.sin(theta), 0, math.cos(theta)).unit
-- Return new unit vector
return newVector
end
You can use this function to get a directional vector with no y rotation. This can be done, for your case, as follows:
local convertedUnit = staticUnitToObjectSpace(Vector3.new(thumbstickX, 0, thumbstickY), camera.CFrame.LookVector)
This will effectively give you a vector which will always be in the direction of the joystick. It could also be converted into a directional CFrame value by solving for an upVector and a rightVector which should be relatively simple, and then creating a CFrame by using the 9 values associated with those vectors. You could also (probably) use other toObjectSpace methods available. Additionally, you could definitely simplify this further to your use case, this was just a general method I created.
If you need more help utilizing this in your code, let me know.