- Home /
Having a game object with two colliders
So I have a custom object, and I would like to have two collision objects to function in the following manner:
A Sphere collider that once a Player intersects, would indicate its an item the player can interact with
A standard box collider with a rigidbody
To assist in determining what is Interactable, I have a component Interactable attached to the first gameobject, that I use to determine what is interactable on OnCollisionEnter().
What I have implemented is a parent element with the first Sphere collider, and a child with the object model, a box collider, and rigidbody. And this approach does not appear to be working. My player intersects the sphere collider and no action is thrown indicating a collision, and furthermore, it often treats that collider as the rigidbody and bounces off.
I'm not clear on how to best address this, so any tips would be appreciated. A screenshot of the game objects in the scene is below.
The method I use to detect collisions is below, and is part of the Player game object.
void OnCollisionEnter(Collision col)
{
if(col.gameObject.GetComponent(typeof(Interactable)))
{
Debug.Log("Collided witrh Interactable: " + col.gameObject.name);
/* if(col.gameObject.name == "Macguffin") {
Debug.Log("Collided with Object");
} */
}
}
Answer by nt314p · Apr 27, 2019 at 11:52 PM
Instead of using a sphere collider, you can check the player's transform distance to interactable items. If that distance is less than a preset value, then the player can interact with the item.
In terms of best performance, should I do the transform check inside the Interactable, or in the Player during a frame update?
Your answer
Follow this Question
Related Questions
I want to know how to wait before I can pick up something 2 Answers
Player not colliding 0 Answers
Help With Colliders 3 Answers
OnDestroy collision detect 4 Answers