1
\$\begingroup\$

I'm trying to create a script to manipulate the transform of a gameobject using the Oculus Touch just as in for instance Quill or Medium, with rotation, translation and scaling. Can somebody help me with this? My initial attempt was to focus on rotation and I got it almost working I think. Here's the code:

void Update()
{
  // On button down
  if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
  {
    originalRotation = transform.localRotation;
    originalControllerRotation = 
      OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);
  }

  // While button is down
  if (OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger))
  {
    var controllerRotation =
      OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch);

    var rotation = originalRotation;
    rotation *= Quaternion.Inverse(originalControllerRotation);
    rotation *= controllerRotation;
    transform.localRotation = rotation;
  }
}

This kind of works but the rotation center doesn't look right. I want it to rotate around the center of the right touch controller and it looks to be rotating around the local origo of the gameobject. How do I modify the code so it rotates around the controller instead?

\$\endgroup\$
0
\$\begingroup\$

I think I know how to do this now. It easiest way seem to be to "parent" my gameobject's transform to the controller transform somehow. I haven't had time to code this yet but I see this a bit more clearly now...

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.