Search Unity

Force landscape rotation when Mobile WebGL is detected.

Discussion in 'Web' started by Rand_D, Aug 11, 2019.

  1. Rand_D

    Rand_D

    Joined:
    Oct 24, 2017
    Posts:
    44
    Hi,

    I have a way to detect when the webgl is opened by touch device successfully. I tried to search around but have not found out a good way to force the WebGL player to rotate to landscape when played by mobile device.

    Can anyone help?

    Thanks,
     
    makaka-org likes this.
  2. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    tantx likes this.
  3. doctorpangloss

    doctorpangloss

    Joined:
    Feb 20, 2013
    Posts:
    270
    Browsers really don't want you to do that, so whatever mitigation you do on a mobile device, it will eventually be banned.

    If you use the BetterMinimal responsive template and just fill the whole screen, you can check if the width is larger than the height. If it is, don't rotate your camera or whatever. Just show a message in your game that says "Rotate to landscape!" and show a little animation of a phone being rotated.
     
    steve-thud likes this.
  4. De-Panther

    De-Panther

    Joined:
    Dec 27, 2009
    Posts:
    589
    hmmmm... when I think about it, he can also rotate the html canvas object
     
  5. Zix83

    Zix83

    Joined:
    Oct 25, 2019
    Posts:
    1
    I can't answer your question but i'm really curious to know how you detect that you're on a touch device on WebGL... I'm trying to do this for ages!
     
  6. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    The solution we found is to use a canvas rect to find out the screen orientation(by comparing x and y), and rotate everything accordingly. we make no distinction if its touch/mobile, we just look at screen size.
     
    r8zbeh likes this.
  7. ewanuno

    ewanuno

    Joined:
    May 11, 2017
    Posts:
    58
    Application.isMobilePlatform works in webgl. i'm checking both that and screen size.

    what are you actually rotating?, i've tried rotating the camera and canvas transforms 90° on the z axis but nothing happens.
     
    Last edited: Apr 23, 2020
    scorp2007 and De-Panther like this.
  8. scorp2007

    scorp2007

    Joined:
    Aug 17, 2014
    Posts:
    54
    actual question, does anyone know a solution? (webgl on andoid/ios)
     
  9. MatheusCohen

    MatheusCohen

    Joined:
    Aug 24, 2017
    Posts:
    57
    Yes, we found a solutions ill ask my dev coworker that found the solution tô share with you
     
  10. xuan_celestial

    xuan_celestial

    Joined:
    Jul 17, 2018
    Posts:
    18
    Hi @MatheusCohen , would like to know your solution of handling this issue is it rotating world canvas UI?
     
  11. ygocmen98

    ygocmen98

    Joined:
    Apr 27, 2019
    Posts:
    9
    Hi how did u solve this problem
     
  12. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
  13. ygocmen98

    ygocmen98

    Joined:
    Apr 27, 2019
    Posts:
    9
  14. gtk2k

    gtk2k

    Joined:
    Aug 13, 2014
    Posts:
    288
    Sorry, I have not Safari device now.
     
    ygocmen98 likes this.
  15. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    547
    Forcing a specific orientation can be achieved by using the ScreenOrientation.lock api. It's supported by all major browsers, except, as usual, by Safari. What you can do, instead, is keep track of the current orientation and update the view accordingly. This approach is supported by all browsers, because you don't lock the orientation, you instead work with it. Try out this asset of mine, maybe it's what you're looking for.
     
    ygocmen98 and De-Panther like this.
  16. ygocmen98

    ygocmen98

    Joined:
    Apr 27, 2019
    Posts:
    9
    thank you i'll try it today
     
  17. QueenLegit

    QueenLegit

    Joined:
    Jun 10, 2020
    Posts:
    5
    It is not available anymore. how do i get it?
     
  18. makaka-org

    makaka-org

    Joined:
    Dec 1, 2013
    Posts:
    1,026
    Here is a new page by author related to changing orientation.

    I also created a separate thread with Unity Assets that support all sensors and modules for WebGL:
    gyroscope, accelerometer, GPS, camera, vibration...

    Current list of Assets:
    • Gyroscope Accelerometer WebGL — enables you to read the gyroscope and accelerometer information provided by the browser.
    • Geolocation WebGL — allows you to access GPS on the web.
    • Device Camera WebGL - allows you to access the camera feed and stream its contents into a render texture (or Texture2D). It works on Chrome, Safari, Firefox, Opera, Edge.
    • Vibration WebGL - enables you to vibrate your mobile phone. You can control how long you want to keep the mobile vibrating, as well as define a vibration sequence.
     
    Marks4 and Gulzat2 like this.