Godot Version
4.3
Question
need help rotating a vector 2 along a sphere in godot to return a vector3 Direction that is along a surface normal can any one help me I'm going insane
I am able to rotate just fine on any other surface but if I were to go to the left or right of a sphere it breaks some one help me.
this is the code
public void Update(Vector2 input_vector, Transform3D camera_transform, Vector3 target_up)
{
Vector3 camera_look = camera_transform.Basis.Z;
camera_look = Util.Vector3.PlaneProject(camera_look, Vector3.Up);
c_angle = Mathf.Atan2(camera_look.Normalized().X,camera_look.Normalized().Z);
Vector3 Result = new Basis(target_up,c_angle + m_angle - Mathf.DegToRad(90)).Orthonormalized().X;
LastMove = Result;
if(m_length > Mathf.Epsilon)
{
m_angle=Mathf.Atan2(input_vector.Normalized().X,input_vector.Normalized().Y);
}
}
What do you mean by “rotating along a sphere”? 3D vectors can only be rotated around axes, and 2D vectors only around 2D points.
I mean when ever i try rotating the input along a normal of a spherical object it starts to break
Describe the exact behavior you’re trying to implement.
I want the update function to make the lastmove variable a vector3 that is in the direction of the vector2 input projected on to the normal relative to the camera with out it breaking
Horizontalize the camera basis and map input components onto basis x and z vectors. Or transform the vector (input.x, 0.0, input.y) into camera basis space and then project it onto horizontal plane.
You say the basis of x and z vectors with the axis being the normal right?
I under stand making the camera horizontal Vector3(cam.basis.z.x,0,cam.basis.z.z)
I dont understand the rest could you maybe elaberate on how to do this?
Multiply camera’s global basis with Vector3(input.x, 0.0, input.y). Nullify resulting vector’s y component and normalize it. That should map your input direction to horizontalized camera basis.
Well i need a vector3 the points to the direction of a the inputs relative to the normal sory if i didnt make that clear not that good at eplaining things
The normal in this case is the target_up variable which is supposed to be a normal from a raycast
Then multiply the said vector with the camera basis and project the result to a plane that has the wanted normal.
Iv’e tried that already my friend.
Your code snippet would suggest otherwise. I don’t see a basis/vector multiplication in there.
I guess not I’ll try it more time
In pseudo-code:
direction = camera_global_basis * Vector3(input.x, 0, input.y)
direction = direction.project_on_plane(plane_normal)
normalize(direction)
The code snippet I just sent doesnt work well either