- Home /
VR: Relative controller position on local axis
Hey,
i ran into another issue i am pretty lost how to solve right now.
The user is standing on a sort of crane platform and has a switch he can flick up or downwards to rotate the platform he is standing on.
Currently i simply store the steamvr controller position in world space at the moment the player grabs the switch.
//store initial position of controller when grabbing
initialControllerPos = hand.transform.position;
//store initial gameObject transform in local, as it is a child of the moving platform
initialLocalObjectRot = transform.localRotation;
initialLocalObjectPos = transform.localPosition;
I then check the relative controller position to the initial grab position to see when the user flicks the switch upwards or downwards.
Vector3 relativePos = initialControllerPos - hand.transform.position;
if (relativePos.z > flickDeadzone)
{
transform.localRotation = flickedUpwardsQuaternion;
leverClickSound.Play();
adapterLever.invokeValue(1);
isFlicked = true;
}
else if(relativePos.z < -flickDeadzone)
{
transform.localRotation = flickedDownwardsQuaternion;
leverClickSound.Play();
adapterLever.invokeValue(-1);
isFlicked = true;
}
This works as intended as long as the player stays on the same axis as the switch - but as soon as the platform rotates i'd need to check if the controler has moved on the z local axis of the switch instead of the general world axis. What puzzles me is how i keep track of the initial grab position of the controller properly moved and rotated with the platform.
If anyone could point me in the right direction, that'd be highly appreciated!
Thanks in advance and have a nice day! Kawalyn