1
\$\begingroup\$

I have a HTC Vive VR set, which has a controller. I have a sphere object, which I want to rotate in a circular motion around my VR Player object, based on the controller grab and its movement. The controller should first grab the object, then it will move left or right, in a circular motion, based on the controller movement. How can I achieve this?


So far, I have made a sphere, with a parent. The parent position is updating with respect to my camera head, so I can move my sphere with my player. The sphere object should move with the controller, but in a circular motion. This has not been achieved, yet, and I really don't know how to do it.

I am able to grip the sphere object using a VRTK script, and I can freely move it, but I want to restrict its movement; much like in the illustrated figure, below:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I think a diagram might help here. There's lots of different ways I could imagine moving something along a circular path, depending on the size & orientation of that circle relative to the player & object. Are you effectively trying to move the object to the point closest to the VR controller while remaining constrained to this circular path? Is your problem in calculating that closest-point-on-circle, or in moving the object to that point? \$\endgroup\$ – DMGregory May 27 '17 at 15:24
  • \$\begingroup\$ @DMGregory Thanks for your comments. Actually i have get stuck in this problem from last one week. Yes you are right, I want to move the object with my controller but in circular shape around my player object. And i am facing problem in both :"calculating that closest-point-on-circle" and " moving the object to that point". as you said. I am also updating my question with picture. \$\endgroup\$ – Muhammad Faizan Khan May 29 '17 at 5:05
  • \$\begingroup\$ @DMGregory i have also added a picture, if you have any query please ask \$\endgroup\$ – Muhammad Faizan Khan May 29 '17 at 5:45
  • \$\begingroup\$ @Gnemlock its ok \$\endgroup\$ – Muhammad Faizan Khan May 29 '17 at 11:46
  • \$\begingroup\$ @DMGregory does the picture make any sense? \$\endgroup\$ – Muhammad Faizan Khan May 29 '17 at 11:46
1
+50
\$\begingroup\$

So you want to restrict the usual spherical movement that occurs as you move the Vive controller around, to a sort of equatorial, planar movement. I'm going to assume that as in this tutorial, your Vive controllers and head are all part of the same transform hierarchy (what they call CameraRig there).

Option A: If you can get the Vive Controller's rotation around the camera (rig). Put sphere into a swivel which is an empty GameObject, having a transform only. Zero the sphere's local position in the inspector. Make sure swivel's transform.position tracks that of the head camera. Set sphere's transform.localPosition=1 to move it slightly forward of the player's head. Set swivel's transform.localEulerAngles.y and .z to the same as the Vive controller's transform.localEulerAngles, but limit transform.localEulerAngles.x = 0 on each sphere Update(). This prevents tilting (up/down) while maintaining heading (north/south/east/west) just like the Vive controller's transform to which it is attached.

Option B: Possibly Simpler. You want that plane / circle to be around your head, and I think it is never tilted (the validity of this answer relies on this fact). In every sphere Update(), set sphere's transform.position.x and .z to that of the Vive controller's transform.position, but set sphere's transform.localPosition.y equal to desired (head camera) y, every frame. You can also set the transform.rotation to the same as the Vive controller, if you need that.

For both options A & B These will superficially work, but you will find that if you look up or down then the sphere will get slightly closer or further away. This is because we are essentially projecting the sphere co-ordinates onto a flat circle. To prevent this i.e. to keep a fixed radius, set sphere's transform.localPosition.z to the distance you want, which might be the distance between the Vive controller and your camera, which is easy to compute, or you could always set it to, say, 1 unit.

Option C: If the sphere is a child of the Vive controller GameObject. Set Vive controller's transform.localEulerAngles.x (or maybe .z) = 0 each frame. Provided your logic runs after the Vive controller's logic, this will do the trick of keeping your object on the circle. Assuming you don't care whether you limit the controller object or the sphere itself, this is the easiest method.

From a mathematical standpoint, we are really just projecting a sphere onto a plane. Between these varied approaches, you should be able to work to a solution. Feel free to ask questions, below.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for your response but answers(option A and b) doesn't make any sense, i guess. by setting only rotation of the sphere i can only maintain its circular position as option 1 suggested. While for option B, the circle should be at head height but move able around 360 of the player using controller. \$\endgroup\$ – Muhammad Faizan Khan May 30 '17 at 12:24
  • \$\begingroup\$ @MohammadFaizanKhan About Option A, you are correct. I have edited the answer. About Option B, this should then do what you suggest, no? Lock it to a circle whose plane is perpendicular to the up-vector of the player's body and head. I've elaborated on both, in any case. \$\endgroup\$ – Engineer May 30 '17 at 12:33
  • \$\begingroup\$ Hi arcane engineer, thanks for your valueable input, i have red your answer 3 or 4 times it seems applicable with some limitation which i will discuss you after the implementation. currently the first option i am implementing. i will let you know its hurdles or limitation soon \$\endgroup\$ – Muhammad Faizan Khan May 31 '17 at 6:42
  • \$\begingroup\$ This is your first option, Right? : 1. Make an empty game object (swivel) 2. Make a sphere object, set it as a child to swivel object with zero position 3. Map cam head position to swivel position (update) 4. Set sphere local postion 1 (so that it comes ahead of the player) 5. Set y and z euler angles of the swivel same as controller but with x euler angles = 0 \$\endgroup\$ – Muhammad Faizan Khan May 31 '17 at 6:43
  • 1
    \$\begingroup\$ Yes i have already done that thanks for your kind support. \$\endgroup\$ – Muhammad Faizan Khan Jun 1 '17 at 7:48

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.