Passing through the Player’s Space

When testing the damage script, you probably noticed that the player and the Slime can push one another around. This is because both GameObjects have Rigidbody 2D Components and exist on the same layer. Naturally, they are colliding with one another and applying force. Amusing as it can be to push the enemies around, it doesn’t quite feel right for this game.

We’re going to make some simple changes to the enemySlime GameObject so that it passes through space occupied by the player but still collides with everything else in the world:

1. Open the Edit menu and select Project Settings > Tags & Layers. If it doesn’t already exist, create a layer named “Enemy.”

2. Open the Edit menu and select Project Settings > ...

Get Learning 2D Game Development with Unity®: A Hands-On Guide to Game Creation now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.