cancel
Showing results for 
Search instead for 
Did you mean: 

Objects not moving in tutorial app (on Quest)

lugosch
Level 2
Hello, Oculus dev noob here. I implemented the app from the "Build Your First App" tutorial, and I'm trying to convert it to actually running on my Quest.

All I did was convert the Camera to an OVRCameraRig and change the Player Controller script to the following:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Oculus.Platform;
using Oculus.Platform.Models;

public class PlayerController : SocialPlatformManager
{

// Appears in the Inspector view from where you can set the speed
public float speed = 500;

// Rigidbody variable to hold the player ball's rigidbody instance
private Rigidbody rb;

// Secondary camera to debug and view the whole scene from above
public Camera spyCamera;

// The OVRCameraRig for the main player so we can disable it
private GameObject cameraRig;

private bool showUI = true;

public override void Awake()
{
base.Awake();
cameraRig = localPlayerHead.gameObject;
}

// Use this for initialization
public override void Start()
{
base.Start();
spyCamera.enabled = false;

// Assigns the player ball's rigidbody instance to the variable
rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
public override void Update()
{
base.Update();
OVRInput.Update();

Vector2 x_y = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
float moveHorizontal = 0.5f; //x_y.x; // 100.0f; //
float moveVertical = 0.5f; //x_y.y; // 100.0f; //
//float moveHorizontal = Input.GetAxis("Horizontal");
//float moveVertical = Input.GetAxis("Vertical");

// Vector3 variable, movement, holds 3D positions of the player ball in form of X, Y, and Z axes in the space.
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

// Adds force to the player ball to move around.
rb.AddForce(movement * speed * Time.deltaTime);
}

void ToggleCamera()
{
spyCamera.enabled = !spyCamera.enabled;
localAvatar.ShowThirdPerson = !localAvatar.ShowThirdPerson;
cameraRig.SetActive(!cameraRig.activeSelf);
}

void ToggleUI()
{
showUI = !showUI;
helpPanel.SetActive(showUI);
localAvatar.ShowLeftController(showUI);
}
}
When I build and run the app on my Quest, I see the ball and box, but the controller inputs don't make anything move, and nothing moves even if I hardcode moveHorizontal and moveVertical (as above). Is there any other step I need to take to get updating to work?

Thanks!
2 REPLIES 2

JeffNik
Level 7
I'm not sure what SocialPlatformManager class is. Try basing your PlayerController class on MonoBehaviour instead, and see if that fixes it.

lugosch
Level 2
Hey JeffNik, evidently SocialPlatformManager is a type of MonoBehaviour that provides a variable called localPlayerHead. I changed my code to use MonoBehaviour:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using Oculus.Platform;
using Oculus.Platform.Models;

public class PlayerController : MonoBehaviour
{

// Appears in the Inspector view from where you can set the speed
public float speed = 500;

// Rigidbody variable to hold the player ball's rigidbody instance
private Rigidbody rb;

// Secondary camera to debug and view the whole scene from above
public Camera spyCamera;

// The OVRCameraRig for the main player so we can disable it
private GameObject cameraRig;

//private bool showUI = true;

private GameObject localPlayerHead;

void Awake()
{
localPlayerHead = this.transform.Find("OVRCameraRig/TrackingSpace/CenterEyeAnchor").gameObject;
cameraRig = localPlayerHead.gameObject;
}

// Use this for initialization
void Start()
{
spyCamera.enabled = false;

// Assigns the player ball's rigidbody instance to the variable
rb = GetComponent<Rigidbody>();
}

// Update is called once per frame
private void Update()
{
OVRInput.Update();

Vector2 x_y = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);
float moveHorizontal = x_y.x; // 100.0f; //0.5f; //
float moveVertical = x_y.y; // 100.0f; //0.5f; //

// Vector3 variable, movement, holds 3D positions of the player ball in form of X, Y, and Z axes in the space.
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);

// Adds force to the player ball to move around.
rb.AddForce(movement * speed * Time.deltaTime);
}
}

But the ball still doesn't move. Any ideas?