0
\$\begingroup\$

I currently have my player object set with a dynamic rigidbody and a box collider, and the object I want it to collide with just has a box collider.

The player is on the Player layer, and the object is on the Items layer.

This is the code I'm using that works for the collision, but I want the collision to work, but allow the player to pass through the object instead of bumping into it.

This is the code I'm using currently;

using System.Collections; using System.Collections.Generic; using UnityEngine; public class DialogueSpawn : MonoBehaviour { public GameObject dialogueBox; private void OnCollisionEnter2D(Collision2D collider) { dialogueBox.SetActive(true); } } 

What am I missing to get this to work? I've been searching for two days for a solution to this problem and I'm not sure where to go from here, because this game is supposed to be a small project for figuring out layer collisions.

\$\endgroup\$
3
  • \$\begingroup\$ Is a trigger what you want? \$\endgroup\$ Commented Nov 23, 2021 at 17:14
  • \$\begingroup\$ I'm trying to avoid triggers as I was encouraged to use layer collision for a reduction in runtime cost. Can layer collision not achieve the same effect? \$\endgroup\$ Commented Nov 23, 2021 at 17:19
  • \$\begingroup\$ Trigger collisions on a given set of layers should be cheaper than non-trigger collisions on the same layers, since the physics engine has to do the same overlap checks either way, but in the trigger case it can skip computing the collision resolution entirely. \$\endgroup\$ Commented Dec 21, 2021 at 18:15

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.