Check if the device has gyro functionality

Hello there.
how can I add a button that will be related to the surface of the sphere, and when I click on this button to open a link.
actually, I know how to add button, but the issue that the button unclickable.
because in the Hierarchy of Zapwork studio, it supposes to be top of the TouchSurface, and the TouchSurface have a script that giving me the option to drag the sphere left and right.
hope you got what is my question!

i think i found the solution, to put the TouchSurface, to be last layer in the hierarchy, and me it invisible.
what do you think, it is right?

2- is there any way, when the user scan zpacode, to make a check, to check if the mobile or the system have gyroscope sensor built in in the device, if yes to show button ( the button of the vr glasses ), if there is no gyroscope sensor buit in the device to hide the vr glasses button !

Hi @eliaskhs,

We have created a new thread for this question as we aim to keep all our threads on our forum to a single topic to help others!

You are indeed correct with making sure that the ‘TouchSurface’ needs to be in the correct position in the hierarchy, if it is not, then it will be unable to be interacted with. Having the ‘TouchSurface’ at the top of the hierarchy will mean that it is above all other components in the scene, therefor allowing pointerdown actions.

In answer to your second question, we do have gyro checking functionality. This can be found on our documentation page under hasGyro(). This piece of code will return a boolean value (True or False) dependant on whether the device has a gyroscope, which in turn you can use to hide/show the VR glasses button.

Hope this helps.

Thanks,

George

Thank you for your respond.
Can you type me the code, what i need to type, in order to check if it has gyroscope or not, i am not professional in thecode parts!
To check if it have gyroscope or not, if it gave to show inage, if not to hide the image!

Thank you for your time.

const VR_switchbutton_png0 = symbol.nodes.VR_switchbutton_png0;

parent.on(“ready”, () => {
// Runs when ready occurs on the parent node
hasGyro(true,flase)
if(true){
VR_switchbutton_png0.show();
}

else{
VR_switchbutton_png0.hide()
}

});

this is waht i tried to type, i am not good in coding part :frowning:
can you correct it !?

Hi @eliaskhs,

You are very close! I’ll give you a few pointers to help you get this finished.

  • Firstly make a variable that is set to true, as an example you can call it gyro. You will compare this to the gyro device check.

  • To get information or to make the device do a specific functionality, you can use Z.device. Adding hasGyro() to the end of Z.device returns a Boolean value (true or false) which can be used in an if statement to compare the variable that was made previously.

  • If the device = the variable that is set as true, then that means that the device does have a gyro and you can show the VR headset. However if it doesn’t have gyro it will return false and will not be equal to the variable meaning the VR headset buttons should be hidden.

Hope this helps,

George

Hello George, you make it hard little bit for me,
you will be helpful if you can send me the code correctly, because i do not have good skills in coding .
i hope you can understand me .
it is 2 minutes from your time, will be like 2 days from my time :wink:
will copy and paste it …

Best regards.
Elias

var VR_switchbutton_png0 = symbol.nodes.VR_switchbutton_png0;
var gyro = true;

gyro = Z.device.hasGyro();

parent.on(“ready”, () => {

if (gyro == true){
VR_switchbutton_png0.visible(false) ;
}
else{
VR_switchbutton_png0.visible(true) ;
}

});

this code showing the gyroscope button on all the devices, even on the devices that do not have gyroscope senor , can you please check it ?

Hi @eliaskhs,

  • Remove “gyro = Z.device.hasGyro();” completely.
  • Then compare Z.device.hasGyro() with your variable of gyro within the if statement.

This should work.

Thanks,

George

var VR_switchbutton_png0 = symbol.nodes.VR_switchbutton_png0;
var gyro = true;

parent.on(“ready”, () => {

if (gyro == Z.device.hasGyro()){
VR_switchbutton_png0.visible(true) ;
}
else{
VR_switchbutton_png0.visible(false) ;
}

});

this code showing that on iphone x there is no gyroscope !
what do you think?

Hi @eliaskhs,

I have tested what you have sent and it works perfectly on mine.

Could you double check that your switch button is definitely called VR_switchbutton_png0 within your hierarchy.

If there is still a problem then please send me your ZPP to Support@Zappar.com.

Thanks,

George