[SOLVED] Orbit camera on mobile and first person view on desktop

Is there a way to setup auto load of orbit camera on mobile, and auto load first person on desktop?

Also, my sound auto plays on desktop, but does not on mobile. Is this a known issue? Or do I need to script auto play for mobile?

Hi @roustan and welcome,

You can have the two controllers (orbit and first person) on two separate entities, initially disabled.

Then use the pc.platform object and its mobile property to check which entity to enable on launch:

// pseudo code
   // enable orbit entity
   // enable first person entity

thank you. what would be the command I’d write to enable orbit entity? I’m a total noob at this stuff.

There are several ways, an easy one is to use the Orbit entity name. Let’s say its name is My Orbit Camera, then do this:

   this.app.root.findByName('My Orbit Camera').enabled = true;
   // enable first person entity

Okay, I made these:
Screen Shot 2023-01-08 at 9.00.31 AM
and then added this script in PC.Platform:

but it just revealed a black screen.

How does it know which object is “first person view”?

I need to be explained to like I’m five honestly :slight_smile:

Hi @roustan! Can you share the editor link of your project so someone can take a look?

Was able to solve by calling up a coder friend to help me:

  • Created 2 controller entities: First Person and an Orbit (First Person above Orbit in the entity tree)
  • Enabled the First Person entity by default - Disabled the Orbit entity by default
  • Created an isDesktop.js script - Attached the isDesktop.js script to the First Person entity
  • Added this code below to the initializer of the isDesktop.js script
var Isdesktop = pc.createScript('isdesktop');

// initialize code called once per entity
Isdesktop.prototype.initialize = function() {
   this.app.root.findByName('First Person').enabled = true;
   console.log("i am on desktop");
    this.app.root.findByName('First Person').enabled = false;
       this.app.root.findByName('Orbit Camera').enabled=true;
       console.log("i am on mobile");
       console.log(this.app.root.findByName('Orbit Camera'));

Nice and thanks for sharing the final solution @roustan!

We should propose that more often in the forum as a solution :innocent:

1 Like