Nodes with two (or more) collision boxes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DoubleCakes
:warning: Old Version Published before Godot 3 was released.

Once upon a time my PlayerChar node only had one collision box that interacted with enemy attacks and walls. The PlayerChar could walk right through enemies though. Instead of making the enemies hurt the player or making it so the PlayerChar couldn’t walk through the normal collision boxes, I’d rather the PlayerChar and enemies to have a slightly smaller collision box that they couldn’t walk through:

enter image description here

I unsuccessfully tried pulling this off by attaching a KinematicCharacter2D node with a CollisionPolygon2D to both enemies and the player and giving the new Kinematics their own Layer and Mask, but that didn’t work. Here’s how the PlayerChar scene looks like:

enter image description here

Before a move forward, I wish for advice on how to approach this.

I’m not sure to understand the objective of the second collider.

You want player and enemies collide each other and both collide the level or player “transparent” to enemies?


ps: That secondary body won’t be affected by move (in the sense of triggering it’s physics collisions) and will work as a regular kinematic body, useful for pushing rigidbodies but not for kinematic collisions.

eons | 2016-12-02 00:05

I’m not sure to understand the objective of the second collider.

It’s just supposed to block the player, just like a wall. Difference is that the player and enemies use that second collider so they can get up a little closer to each other compared to regular walls.

DoubleCakes | 2016-12-14 21:37

:bust_in_silhouette: Reply From: eons

It won’t work because collision detection wont be updated on the inner kinematic body (is not a joint but 2 separate bodies, one moving, the other dragged by the parent), you can add an Area2D instead and simulate a collision with area_enter signal or get_overlapping_areas.

But I think that will work better if the small body is the parent kinematic and the bigger is an area (or a set of raycasts).


And there is a way to “move” 2 bodies at once but is kind of hacky:
Put the children inside a plain Node, the children of Node will not be affected by parent’s transformations.

KinematicBody2D
|-Sprite
|-CollisionPolygon2D
|-Node
   |-KinematicBody2D
      |-CollisionPolygon2D

Then, when you move the body in the script, you will need to move “Node/KinematicBody2D” too, and check both for collision.
I don’t like it, it could get messy in some cases, but may work.

that’s a cool idea, let me try this too, thanks eons

ruruarchy | 2019-11-06 03:29