Hi everyone,
I am trying to make something where you stretch out a primitive object like a box with controllers, but I am having difficulty with rotation and orientation. I have made it so on a trigger it creates a box, parents it to a null which is placed at one corner of the box, and is positioned at the triggered controller. Then you press the trigger for the other controller and you can expand the nulled box out (it scales between the two controllers).
Here is what is happening in the Update (C#), I have been trying out of VR at the moment with two GameObjects, pointA (left controller) and pointB (right controller):
void Shape_FrameUpdate()
{
if (activeShape_null != null)
{
activeShape_null.transform.position = pointA.transform.position;
float newx = activeShape_null.transform.position.x - pointB.transform.position.x;
float newy = activeShape_null.transform.position.y - pointB.transform.position.y;
float newz = activeShape_null.transform.position.z - pointB.transform.position.z;
activeShape_null.transform.localScale = new Vector3(newx, newy, -newz);
}
}
So far this works fine as a start
Point A is bottom left, Point B is top right… however because I am using x,y,z positions I have this weird world position lock where it always a box facing forward… I’m looking to have it more natural where the rotation of the box is based on the rotation of both the controllers, kind of like how you see it briefly at 25 seconds at this Leap Motion demo…
I know I haven’t added any code for rotation yet, I’ve tried Quaternion.LookRotation, LookAt and FromToRotation, but I can’t seem to get it to work alongside the scaling code which I’m doubting is the right approach…
Hope it makes sense, any help is much appreciated!