0 votes

I've got an enemy RigidBody2D on Layer 1 / Mask 1, while the player KinematicBody2D is on Layer 0 / Mask 0. The StaticBody2Ds they stand on are on both Layers and Masks 0 and 1.

The enemy has an Area2D on Layer 0 which detects when the player enters and applies a fixed impulse which causes it to jump.

It jumps roughly the same height every time, unless the player enters that area from above, in which case it jumps half that height every time.

Here's a video of it in action: you can see that the enemy does clip through the player cleanly when landing.

Can anybody think of common or expected reasons why PhysicsBody2Ds which should be on separate layers appear to be affecting each others' physics?

in Engine by (103 points)
edited by

1 Answer

+1 vote

The difference between masks and layers are:

The mask decides which layers it'll collide.
The layer decides which masks will collide with it.

This means that your player will collide with the enemy because this enemy is in Layer 1. At least that is what I've seen in my experiences. Related:

https://godotengine.org/qa/3020/collision-masks-and-its-propper-uses
https://godotengine.org/qa/4010/whats-difference-between-collision-layers-collision-masks

Edit:
Then it's a error somewhere in the code you made to make a KinematicBody interact with a RigidBody. I'm certain you did a interaction code, right?

by (1,120 points)
edited by

Sorry, sorry, serious typo on my part! The Player is Layer 0 / Mask 0 and the Enemy is Layer 1 / Mask 1.

Though it did take me a while to wrap my head around the differences between Layers and Masks, so that is a helpful post.

I'll scour the code in case I missed something, but by design the KinematicBody2D should not interact with the RigidBody2D.

I have Area2Ds on each object that handle interactions, that way they can specifically stay separate on the physics layers but still detect overlaps of each other. The Area2Ds are on the same layer and behave as expected. The PhysicsBody2Ds ought to be unrelated.

I'll see if I can reproduce this phenomenon with a more minimal example.

Edit I'm still digging in, but it's interesting that the RigidBody2D behaves as expected if I set cansleep to false. Or, bizarrely, if I setsleeping(true) just before the apply_impulse call.

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.