Ouya can't recognize the controller input

UnisonGamesUnisonGames Posts: 15Member
I am trying to move a box around the screen using a control stick. It works (kinda) on my computer with the a and d keys but when I put it on the ouya the box won't move and periodically falls through the terrain. And I don't know what the problem is.

Here is my code:

using UnityEngine;
using System.Collections;

public class Controller : MonoBehaviour
{

    public float speed = 1.0F;
    public float gravity = 20.0F;
    private Vector3 moveDirection = Vector3.zero;
    public CharacterController controller;
    private string Developer_ID = string.Empty;

    //OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent> buttonListener = new OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>();


    void Awake()
    {
        try
        {
            OuyaSDK.initialize(Developer_ID, false);

            OuyaSDK.registerInputButtonListener(new OuyaSDK.InputButtonListener<OuyaSDK.InputButtonEvent>()
            {
                onSuccess = (OuyaSDK.InputButtonEvent inputEvent) =>
                {
                    OuyaInputManager.HandleButtonEvent(inputEvent);
                },
                onFailure = (int errCode, string errMessage) =>
                {
                    //failure code
                }
            });

            OuyaSDK.registerInputAxisListener(new OuyaSDK.InputAxisListener<OuyaSDK.InputAxisEvent>()
            {
                onSuccess = (OuyaSDK.InputAxisEvent inputEvent) =>
                {
                    OuyaInputManager.HandleAxisEvent(inputEvent);
                },
                onFailure = (int errCode, string errMessage) =>
                {
                    //failure code
                }
            });

        }
        catch (System.Exception ex)
        {
        }
    }

    void Update()
    {

        Vector2 point = deadZoneCheck(OuyaInputManager.GetAxis("LX", OuyaSDK.OuyaPlayer.player1), OuyaInputManager.GetAxis("LY", OuyaSDK.OuyaPlayer.player1), .15f);

        if (controller.isGrounded)
        {

            moveDirection =  new Vector3(1 * point.x * speed, 0f, 1 * point.y * speed);
Debug.Log("Point x: " + point.x);
Debug.Log("Point z: " + point.y);
Debug.Log("Speed: " + speed);
        }
        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
    }
    private Vector2 deadZoneCheck(float x, float y, float radius)
    {
        Vector2 result = new Vector2(x, y);
        bool isInDeadZone = testDeadZone(x, y, radius);
        if (isInDeadZone)
        {
            result.x = 0f;
            result.y = 0f;
        }
        return result;
    }
    private bool testDeadZone(float x, float y, float radius)
    {
        float distance = Mathf.Sqrt((x * x) + (y * y));
        return distance < radius;
    }
}

Comments

Sign In or Register to comment.