How to collide without a Box Collider?

Plain and simple, I want a way to detect if my player picks up an item, but that item shouldn’t have a box collider as the player should be able to walk through it as with any game.

But at the same time I need to detect if the player has touched that item. How do I detect this while keeping the box collider component turned off so that I can get the player to be able to walk through it? :slight_smile:

You can mark the collider with a layer that does not collide with the player but is detectable by raycast. You can configure physics to not collide any two arbitrary layers (Edit-> ProjectSettings-> Physics).

OR you can just use Vector3 to see if the player is close enough using Vector3.Distance().

1 Like

You could also use a trigger collider.

2 Likes

Thank you both!

I just did the first method you told, I unchecked the box where the player’s layer and the pickable meet. It works wherein that I can go through it, but the collision doesn’t get detected. :frowning:

Hello

Set “IsTrigger” to true and you can walk trough but you also can detect a collision.

christoph

1 Like

I just tried it but it still doesn’t detect as there is no touching between the two objects. Maybe I’m missing something?

I am using OnTriggerEnter in your case.

Hello

Try OnTriggerEnter2D and check the size of the Colliers.

Christoph

Tried that as well, still no dice. :frowning:

Do you still have the collision layer between the player and the pickable unchecked?
You would have to re-check the box, since you’re now trying to detect intersections between these layers.

1 Like

Ah I see, but I just re-checked it and I am still able to move through it and the collision detection isn’t working. Hmm…
Maybe I have to do something with the new layer I made? Sorry, new to this.

For trigger collision to be detected one of the objects needs to have a Rigidbody on it (set it to kinematic and don’t use gravity if you want to control how it moves). You then need to use OnTriggerEnter or OnTriggerEnter2D (depending if you’re doing 3D or 2D) and put your collision code in there.

1 Like

The player has a rigidbody, but since the player moves through the pickable (which has its own layer after the player), the collision doesn’t work. I tried everything that was said here and what I got from it so far is that the collision doesn’t detect if the player doesn’t touch the physical object, so when there’s a layer and the player could go through the object, collision doesn’t get detected. I need a way around this, maybe the layer I made and the position of the layer is wrong?

Nvm, my bad, I fixed it. The mistake was:

  1. I didn’t uncheck the box in the physics setting as @Vryken said.

It still didn’t work.

  1. I had to then change the OnTriggerEnter variable type from Collision to Collider, which then works!

Thank you all. :smile:

2 Likes