0 votes

I'm working on a 2d platformer, and I'm building a companion character to help my Player fight enemies. I want it to be able to walk right through my player, but still collide with things like the floor, walls, enemies, and projectiles.

right now I've built my companion as a KinematicBody2d with an AnimatedSprite and rectangle CollisionShape2d. I tried making the CollisionShape2d have a One-Way-Collision, and at least this mostly keeps it from getting in the way of my Player (the Player can just push the companion around), but I want it to be able to pass right through my Player and run directly to the enemy.

How can I accomplish this?

asked Aug 7 in Projects by GilbyScarChest (16 points)

1 Answer

+1 vote

You want to utilize the collision layer and collision mask.

To make things easier, you'll probably want to name the layers. See https://docs.godotengine.org/en/3.1/tutorials/physics/physics_introduction.html#collision-layers-and-masks for details on setting this up. Given your description, you probably want a layer for: player, npc, floor, walls, enemy, and projectile

Now, for each of these entities, you'll want to select the "collision layer" that matches what the entity is. So for the player, you want to select the player bit. For floors, you want to select the floor bit.

The "collision mask" indicates which types of things that entity is able to collide with. So for example, for the npc, you would want to have all the things selected except player, this way the npc can pass through the player.

answered Aug 7 by Eric Ellingson (578 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.