cancel
Showing results for 
Search instead for 
Did you mean: 

OnTriggerEnter() not working in Oculus Go environment?

mmdem0
Level 2
Hey guys,

I really need help on this. I have tried so many forums to get an answer, and nobody has helped. I have five triggers set up in a scene to call an object to go to a starting position, to follow the player for a certain amount of time, then to move off to an end position. I also have triggers that trigger animations of three separate fish, which are supposed to jump over you. None of these work. I have it all set up correctly according to every forum I've searched. I have rigid bodies, mesh colliders, convex on, I made sure that everything is set up in the physics map to collide, etc. It still won't work. It won't even enter the OnTriggerEnter() function, as I even put in a visual debug code. Here is some example code of what I am doing:
//fish controller
public class FishController : MonoBehaviour
{
    public Animator fishAnimator1;
    public Animator fishAnimator2;
    public Animator fishAnimator3;
    void Start()
    {
        fishAnimator1 = GetComponent<Animator>();
        fishAnimator2 = GetComponent<Animator>();
        fishAnimator3 = GetComponent<Animator>();
    }
    public void TriggerFishAnimation(int i){
        if(i == 1)
        {
            fishAnimator1.SetTrigger("FishAnimation");
        }
        if(i == 2)
        {
            fishAnimator2.SetTrigger("Fish2Animation");
        }
        if(i == 3)
        {
            fishAnimator3.SetTrigger("Fish3Animation");
        }
    }
}

//Bird targets
public class BirdTargets : MonoBehaviour
{
    [SerializeField]
    AnimatedBird[] birds;
    [SerializeField]
    Transform startPosition1;
    [SerializeField]
    Transform startPosition2;
    [SerializeField]
    Transform playerFollow1;
    [SerializeField]
    Transform playerFollow2;
    [SerializeField]
    Transform endPosition1;
    [SerializeField]
    Transform endPosition2;

    void Awake() {
    }

    public void BirdsToStartPosition()
    {
        birds[0].SetDestination(startPosition1.position, 10f);
        birds[1].SetDestination(startPosition2.position, 10f);
    }
    public void BirdsToFollowPosition()
    {
        birds[0].SetDestination(playerFollow1.position, 0.1f);
        birds[1].SetDestination(playerFollow2.position, 0.1f);
    }

    public void BirdsToEndPosition()
    {
        birds[0].SetDestination(endPosition1.position, 0.05f);
        birds[1].SetDestination(endPosition2.position, 0.05f);
    }
}

//Animated Birds
public class AnimatedBird : MonoBehaviour
{  
    [SerializeField]
    int targetNumber;
    [SerializeField]
    float smoothSpeed;
    DemoMovementRig rig;
    Vector3 targetPos;
    public Vector3 startingPos {get; private set;}
    // Start is called before the first frame update
    void Start()
    {
        rig = FindObjectOfType<DemoMovementRig>();
        targetPos = this.transform.position;
    }
    // Update is called once per frame
    void Update()
    {
            FlyToTarget(); 
    }
    void FlyToTarget()
    {
        transform.LookAt(targetPos);
        transform.position = Vector3.Lerp(transform.position, targetPos, smoothSpeed * Time.deltaTime);
    }
       public void SetSpeed(float f)
    {
        smoothSpeed = f;
    }
    public void SetDestination(Vector3 v)
    {
        targetPos = v;
    }
    public void SetDestination(Vector3 v, float s)
    {
        targetPos = v;
        smoothSpeed = s;
    }
}

//eventcontroller
public class ZiplineEventsController : MonoBehaviour
{
    AnimatedBird[] Birds;
    BirdTargets birdTargets;
    FishController fishController;
    void Awake(){
        Birds = FindObjectsOfType<AnimatedBird>();
        birdTargets = gameObject.GetComponent<BirdTargets>();
        fishController = gameObject.GetComponent<FishController>();
    }
    public void BirdEvents(string s)
    {
        if(s.Equals("start"))
        {
            birdTargets.BirdsToStartPosition();
        }
        else if(s.Equals("follow"))
        {
            birdTargets.BirdsToFollowPosition();
        }
        else if(s.Equals("end"))
        {
            birdTargets.BirdsToEndPosition();
        }
        else
        {
            //used for visual debugging
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.position = new Vector3(-4.31f, 35.47f, 40.97f);
            cube.transform.localScale = new Vector3(5.0f, 5.0f, 5.0f);
            //Debug.LogError("Bird events broke.");
        }
    }
    public void TriggerFishAnim(int i){
        fishController.TriggerFishAnimation(i);
    }
}

//demomovementrig
public class DemoMovementRig : MonoBehaviour
 {
        public Transform startingPostion;
        public Transform endingPosition;
        ZiplineEventsController zipEvents;
        BirdTargets[] birdTargets;
        [SerializeField]
        float speedModifier;
        bool enableMovement = false;
   
        //following four functions all work
        void Awake() {
            zipEvents = GetComponent<ZiplineEventsController>();
        }
        void Start()
        {
            enableMovement = false;
            this.transform.LookAt(endingPosition);
        }
        // Update is called once per frame
        void Update()
        {
            if(enableMovement)
            {
                TranslateCharacter();
            }
        }
        //draws the line that the user follows
        void OnDrawGizmos() {
            Gizmos.color = Color.red;
            Gizmos.DrawLine(startingPostion.position, endingPosition.position);
        }

        //these do not work
        void OnTriggerEnter(Collider other) {
            if(other.gameObject.CompareTag("EndTrigger"))
            {
                ResetPosition();   
            }
            if(other.gameObject.CompareTag("BirdsStart"))
            {
                zipEvents.BirdEvents("follow");
            }
            if(other.gameObject.CompareTag("BirdsStop"))
            {
                zipEvents.BirdEvents("end");
            }
             if(other.gameObject.CompareTag("Fish1"))
            {
                zipEvents.TriggerFishAnim(1);
            }
            if(other.gameObject.CompareTag("Fish2"))
            {
                zipEvents.TriggerFishAnim(2);
            }
            if(other.gameObject.CompareTag("Fish3"))
            {
                zipEvents.TriggerFishAnim(3);
            }
        else
        {
            //used for visual debugging
            GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
            cube.transform.position = new Vector3(-4.31f, 35.47f, 40.97f);
            cube.transform.localScale = new Vector3(5.0f, 5.0f, 5.0f);
        }//end of else
        } // end of on trigger enter

        public Vector3 GetBirdTargetPos(int i)
        {
            if (birdTargets != null)
            {
                return birdTargets.transform.position;
            }
            else
            {
                Debug.LogError("Position not correctly fetched");
                return Vector3.zero;
            }

        }
//other functions in class control buttons, which work but I did not include to save space
    }

Please someone help me figure out why this code isn't working I've been staring at it for over two weeks
2 REPLIES 2

catskull
Level 2
I have the same issue... none of my trigger callbacks function. Development for the Oculus is infuriating; it's haphazard and the tooling stinks. 

Aurelinator
Level 3
I don't think this has anything to do with Oculus. It's a matter of using Unity. Have you tried simplifying the problem? Whenever I have issues like this, it's usually something odd. So I boil it down to a simple thing - can I get a... falling cube, to fall through another cube (that is a trigger) that has a script and fire the OnTriggerEnter? 

In order to trigger that, the following conditions must be met: Both objects must have colliders, one of the objects must have a rigidbody (in this case the falling cube). If you can get that working, you can slowly try to understand what about your current set up is not working.