InverseTransformPoint() help
I am making a script for the HTC VIVE. In my script, i am trying to find the distance between two points on an objects local axis and use this value to set the position of another object. I am attempting to achieve this using the InverseTransformPoint() function to get the distance. The current setup is as follows
I have an object(we will call object1) and childed on that object are point a and point b. Point a is static,and is the point from which I am measuring the distance. point b is what I am trying to set based off of the distance measured. I am using the vive controller as the last point(point c) and it is the second point in the distance calculation
so in theory what I want to have happen is, on a local scale i want the distance between point c (not a child of object1) and point a (is a child) to be measured; then using that measurement I want point b to be set that distance away from point a. thus setting it where the controller is but in the local space of object1.
the issue I am running into is that the point b is getting set 3.47 times further than it should which I think is due to the distance being calculated on the wrong scale. as a temporary fix I just divided by 3.47, but I'm trying to make the system reusable, and having to manually calculate this offset every time would be tedious. The code I am using is as follows:
//calculating the distance between c and a
controllerDistance = (object1.InverseTransformPoint(pointa.position).z - object1.InverseTransformPoint(pointc.position).z);
later in the code
//offset should = the direction and magnitude point b needs to move
offset = Quaternion.AngleAxis(pointa.transform.rotation.y, pointa.transform.up) * pointa.transform.forward * (controllerDistance);
pointb.position = pointa.transform.position + offset;
please help me out I've been stuck on this for days now
setting it where the controller is but in the local space of object1
If pointb is child of object1, you can just: pointb.localPosition = pointc.position
If pointc is the controller in worldspace.
That was my first attempt, but sadly since the object1's rotation is constantly changing, I needed to use the method outlined above to account for that. setting the pos as you have outlined gives me different positions for the same distance depending on the objects rotation. all I really need to figure out is what is causing the distance to be increased by the 3.74 that it is