Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Unity newbie question: disabling collisions?

A topic by Qory created Nov 24, 2022 Views: 203 Replies: 1
Viewing posts 1 to 2

Hello. I have a project I'm making in Unity with c#. I have a couple objects with a Rigidbody2D and BoxCollider2D component each (a player and enemy for this case, but it's also affecting a few other things...). With this logic, I have it set within the OnCollisionEnter2D function that if an object is a certain layer (i.e. in the enemy and player are set for each other on theirs), then Physics2d.IgnoreCollision is called. While this works good for after the initial impact, there's still an initial "bump" that happens, letting the player do stuff like run into enemies and push them off a cliff, smack into a hurtbox before being damaged, etc.

Is there a different function I should be calling in order to stop this initial "bump?"

Do you mean you don't want the player and enemy to be able to touch each other?

If I understand correctly, I think you may want to just delete the IgnoreCollision part and replace it with something like:

if (//whatever specific way you used to check the layer)
{
    return;
}

Or I might still be misunderstanding your problem.