Kinematic2D (Player) with more than one collisionShape2D with independent collision layers and collision masks?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By arthurZ

Hi, I’m creating a character with KinecmaticBody2D that needs multiple colliders but each one will collide with different things. Like a fighting game, with a collision box for the body contact, other for the head, and so on. If it’s not possible by default, is there any advice on how to approach this?

What I need is like in this video (the blue and green boxes):

I found this QA and I did what the last person said and put one KinematicBody2D inside another KinematicBody2D, but this become too ugly. LOL

https://forum.godotengine.org/10408/nodes-with-two-or-more-collision-boxes

:bust_in_silhouette: Reply From: TyTYctA

I think the green box is collsision shape of KinematicBody.
Red and Blue box is collision shape of Area2D. and when enemy overlap Area2D’s collision shape, it will be taken damage.

:bust_in_silhouette: Reply From: RenenerG

You see 3 types of rectangles in the video:

Green: KinematicBody2D

This is basically the player controller, which handles movement and collisions, like the one in the Platformer demo. It usually collides with the level, but not with the blue or green rectangles.


Blue: Area2D
Represents the “Hitbox” of the corresponding player. It can for example register other overlapping Area2D nodes, like the red rectangles.


Red: Area2D
Represents some kind of “source of damage”, it is basically an Area2D node, wich is registered from hitbox-areas. It could be a script attached to it, with stats for the dealed-damage. The Hitbox could get these stats, when the signal area_entered is fired, with something like this:

if _on_Hitbox_area_entered(area):
    if area.has_method("get_damage"):
        var damage = area.get_damage()
        print(owner.name + " takes " + str(damage) + " damage!")

Here, you need to know, how to use Signals.


simple Example scene:

KinematicBody2D(Player)
    AnimationPlayer, Sprites, AudioStreamPlayer, or whatever you need too
    Node2D(Hitboxes)
        Area2D
        ...
        ...
    Node2D(DamageSource)
        Area2D
        ...
        ...

How it could work:

The KinematicBody2D is just the player controller, like mentioned above. The player controller allows different input for different attack-animations. A simple punch-animation would just show up a DamageSource for a short period of time, so the other characters Hitbox could register a collision with it, so the character can take damage.

Here, you need to know, how to use Animations.
Also I suggest you to have a look at the Phyics introduction.

Good luck! :slight_smile:

Thanks man. Just one more thing, is that possible to use the Area2D to have a second body collider? I mean, like setting the corresponding layers and masks can I also use CollisionShape2D from an Area2D to act like the KinematicBody2D main CollisionShape2D? I mean, this to represent the character’s body too and that will contact and push some enemies while KinematicBody2D’s CollisionShape2D can push others or one for the static bodys (ground and walls) and other for the enemies?

arthurZ | 2019-02-27 14:04