Log in or register to post comments

Moving object containing ARCamera works in Preview but not on device

November 26, 2016 - 5:18pm #1

Not sure where's the right place to put this, so trying here!


I'm developing an AR app where the player is moving through a dungeon. I'm using a button for forward movement and another for backwards movement. The idea is that the player will move the phone around to look ("rotating" left and right), then press "Forwards" to move forwards. The player might have multiple weapons equipped, so I placed the ARCamera within an empty GameObject named "Player" that has a Rigidbody and Capsule Collider. The hierarchy is as follows:

  • Player (GameObject), with Rigidbody and Capsule Collider
    • ARCamera
      • Camera, with its children; nothing changed at this level after dragging the AR Camera into the project.

I have code that runs when the "Forward" button is pressed, which translates the Player GameObject in the direction the ARCamera's pointing, as follows (C#):

float playerSpeed = 0.2f;

GameObject player = GameObject.Find("Player");

GameObject cam = GameObject.Find("ARCamera");

Vector3 v = new Vector3( cam.transform.forward.x, 0, cam.transform.forward.z );

player.transform.Translate( v * playerSpeed );

This works perfectly in Preview.

When I build this for my Android phone (Moto G4 running Android 6.0.1, Kernel 3.10.84-g061c37c, build MPJ24.139-64) and run it there, pressing the "Forward" button does nothing. Everything else works exactly the same as in Preview.

Any ideas?

Log in or register to post comments