+1 vote

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):
https://www.youtube.com/watch?v=sAeoK3y33fo

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://godotengine.org/qa/10408/nodes-with-two-or-more-collision-boxes

in Engine by (172 points)

2 Answers

0 votes

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.

by (312 points)
+2 votes

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! :-)

by (252 points)

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?

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.
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 webmaster@godotengine.org with your username.