SignedAngle works properly with transform.position but not transform.localPosition

I’m working on a VR motorcycle game and trying to get the steering to work by the player grabbing and rotating the handles. The steering works because of the function "CalculateRotation() (in the code block below) which gets the angle between the hands and rotates the handlebars/the bike based on that.

When “transform.position” is used for the controller positions it works smoothly (the handlebars smoothly rotate to the controller positions), but when “transform.localPosition” is used it freaks out (the handlebars rotate away from the controller positions as far as they can - 50degrees because the "maxRotation variable clamps the rotation to 50degrees) so you can’t actually grab onto the handlebars.

I would just use “position” but when the bike starts moving it can’t calculate the angle properly and the handlebars start acting like they do with “localPosition”.

I either need to figure out why “localPosition” doesn’t work or figure out how to make “position” work when the bike is moving. But I would like to have some insight on why “localPosition” isn’t working since if I can figure out why it’s an issue I can likely solve it.

Some more info:
I tried using transform.TransformDirection/TransformPoint/TransformVector & the inverses but they didn’t seem to help. Also the handlebars and the controllers are children of different gameobjects so I think that may be a part of why the localPosition doesn’t work but I’m not sure. Any suggestions would be appreciated.

private Quaternion CalculateRotation()
    {

        //hand xz + source y (to stay consistent)
        //use these positions to figure out do the math for rotation
        //USE POSITION NOT LOCALPOSITION FOR IT TO WORK


        /*leftControllerPos = leftController.transform.InverseTransformDirection(leftController.transform.position);
        rightControllerPos = rightController.transform.InverseTransformDirection(rightController.transform.position);
        leftSubPos = leftSub.transform.InverseTransformDirection(leftSub.transform.position);
        rightSubPos = rightSub.transform.InverseTransformDirection(rightSub.transform.position);*/

        leftControllerPos = leftController.transform.position;
        rightControllerPos = rightController.transform.position;
        leftSubPos = leftSub.transform.position;
        rightSubPos = rightSub.transform.position;

        //check which hands are detected to get targetDir
        Vector3 firstPos;
        Vector3 secondPos;
        if (detectedHands == DetectedHands.BothHands)
        {
            Debug.Log("BothHands");
            firstPos = leftControllerPos;
            secondPos = rightControllerPos;
            Debug.Log("firstPos = " + firstPos + "\nsecondPos = " + secondPos);
        }
        else if (detectedHands == DetectedHands.LeftHandOnly)
        {
            Debug.Log("LeftHandOnly");
            firstPos = leftControllerPos;
            secondPos = rightSubPos;
        }
        else if (detectedHands == DetectedHands.RightHandOnly)
        {
            Debug.Log("RightHandOnly");
            firstPos = leftSubPos;
            secondPos = rightControllerPos;
            Debug.Log("firstPos = " + firstPos + "\nsecondPos = " + secondPos);
        }
        else
        {
            Debug.Log("None");
            firstPos = leftControllerPos;
            secondPos = rightControllerPos;
        }

        //do math with correct targetDir
        Vector3 targetDir = secondPos - firstPos;
        Vector3 right = transform.right;

        float angle = Vector3.SignedAngle(targetDir, right, Vector3.up);

        angle = Mathf.Clamp(angle, -maxRotation, +maxRotation);
        AdjustedAngle = -angle;

       

        //visualizeDirection.transform.localRotation = Quaternion.Euler(new Vector3(0, -angle, 0));
        //Quaternion bikeRotation = FindObjectOfType<BikeController>().transform.localRotation;
        Quaternion firstRot = Quaternion.Euler(new Vector3(-24, 0, 0));
        Quaternion secondRot = Quaternion.Euler(new Vector3(0, AdjustedAngle, 0));
        Quaternion adjustedRotation = firstRot * secondRot; //bikeRotation *
        Debug.Log("adjustedRotation = " + adjustedRotation);
        return adjustedRotation;
    }

This is not physics (there are no Physics features discussed here), it’s just Scripting using Transforms. I’ll move your post to the Scripting forum.

Do you understand the difference between position and localPosition?

position is global coordinates, localPosition is relative to the local transform space.