- Home /
Help with VR Controller Collider
Hey Guys,
I've been really stuck on a problem. I have a basic home in Unity3d and I am trying to add a lightswitch that the person can touch with their SteamVR Controller to turn on and off the lights. But I am not able to get an OnTriggerEnter event to fire when passing the controller through the lightswitch.
My lightswitch is a box collider. I've tried it with a rigid body and without. And as isKinematic and not.
I have a sphere collider and a rigidbody attached to the model under both Controller(left) and Controller(right) of the CameraRig Object.
Finally, I have the following Script Attached to the Models, but have also tried it on the switch.
using UnityEngine;
using System.Collections;
public class SwitchCollision : MonoBehaviour {
void OnCollisionEnter(Collision col)
{
Debug.Log("Switch Collision");
}
void OnTriggerEnter(Collider col)
{
Debug.Log("Switch Trigger");
}
}
I can't get either to print. Can you see what I am missing?
Hi, maybe colliders are on a different layer: check the layers the gameobjects are assigned to and the layer collision matrix in edit/projects settings/physics
Answer by TOOVISUAL · Feb 09, 2017 at 09:52 PM
This is a little buggy but if you add a character motor to the controller it will work. By buggy I mean if you put it on both hands it will error when you grab the same object with both hands. You will also want to bring in the size of the character motor and you dont need the character controller after you put it on, you only need the character motor.
Also use this scrip and make sure your light is on on public and then also make sure you drag your light onto this script once you have attached it to your triggering collider.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class turnofflight : $$anonymous$$onoBehaviour
{
public Light light;
void OnTriggerEnter()
{
light.enabled = false;
}
void OnTriggerLeave()
{
light.enabled = true;
}
}
Your answer
Follow this Question
Related Questions
2d game end level with trigger and colission with trigger who to make a if condition 1 Answer
How do I make animation transitions a one-way street? 1 Answer
My trigger is called twice 1 Answer
OnTriggerEnter not working all the time. 2 Answers
Animate gameobject when collided with another gameobject using VRTK 0 Answers