Basic collision detection Help

Hello. I am quite new to this language of coding, and am looking for some help. In Unity, I have 2 sprites that have a capsule collider (the character) and a box collider (bricks). Both colliders also have “is trigger” enabled. I am trying to detect if the character moves into the bricks as I already made a movement script.
This is my code so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class collision : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}
// Update is called once per frame
void Update()
{

}

private void OnCollisionEnter2D(Collision2D collision)
{
    print("touching");

}

}

However, when attaching this script to both sprites, I do not get anything printed to the console. Any help is appreciated! :slight_smile:

Since they are triggers you should you OnTriggerEnter. Furthermore, your setup implies that you are using 3D colliders, hence 2D versions of collisions and triggers wont work.

Read more on OnTriggerEnter

Alright I got it to work. First I changed OnCollisionEnter2D to OnTriggerEnter2D.
After reading some of the documentation of OnTriggerEnter, I realized that my sprites needed rigid bodies, so I added them to both of my sprites and set them to “kinematic” so they wouldn’t be affected by gravity, but would still have collision detection. After doing this, moving my character into the bricks will now give me a “touching” printout in the console. Thanks @revolute!