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