The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

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?

in Engine by (17 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.

by (1,663 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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.