I'm pretty new to VR development with Unity, what I need to do is to grab a clockwork object and rotate it around its pivot by moving the right hand controller, like if I had to do that in real life
Here's the scenario:
Here's the code I'm using in Update:
public class Box1: MonoBehaviour {
public Transform rightHandTransf;
Vector3 handPosition;
void Update(){
Vector3 rhPos = rightHandTransf.position;
Quaternion rhRot = rightHandTransf.rotation;
// clockworkM Rotation
rhPos.z = clockworkM.transform.position.z - Camera.main.transform.position.z;
handPosition = Camera.main.WorldToScreenPoint(rhPos);
clockworkM.transform.rotation = Quaternion.LookRotation(Vector3.back, handPosition - clockworkM.transform.position);
}
}
What I get is that wherever I move the hand, the clockwork rotates just a little bit, and if I rotate the headset, the clockwork rotates based on my X axis rotation with my headset
Weird behavior, I have no idea what I'm doing wrong :(
you probably solved it by now but in case someone else stumbles on this. My solution is just for rotating object around Y axis but can be easily edited for any other direction: