Looks like you're not logged in

Login or Register to continue

Lesson Q&A

Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.

  • Hurt- and Hitbox ProblemsCodingWork23I have a problem that the enemy ignores everthing he interacts. I have tried set brakepoints on the Hitbox and Hurtbox to see in wich team they are. Sometimes the Hitbox of the enemy on the function `_on_area_entered()` he gets an area that is null. I find out that only the enemy's Hurt- and Hitbox interact eachother. Of course nothing happend, because they are in the same team. HitboxArea2D ```gdscript class_name HitBoxArea2D extends Area2D enum Teams {PLAYER, ENEMY} export(Teams) var team := Teams.PLAYER export var damage := 1 # if "true", this hitbox can hit multiple targets export var can_hit_multiple := false func _ready() -> void: connect("area_entered", self, "_on_area_entered") func apply_hit(hurt_box: HurtBoxArea2D) -> void: # if in the same team --> ignore if hurt_box.team == team: return # hurtbox gets the damage hurt_box.get_hurt(damage) # If this hitbox can only hit one target, we turn off its `monitoring` # property. # We use `set_deferred()` to do so because we can't toggle the property # while the engine is processing physics. set_deferred("monitoring", can_hit_multiple) func _on_area_entered(area: HurtBoxArea2D) -> void: if not area: return apply_hit(area) ``` HurtboxArea2D ```gdscript class_name HurtBoxArea2D extends Area2D signal hit_landed(damage) enum Teams {PLAYER, ENEMY} export(Teams) var team := Teams.PLAYER # an entity may have some armor rating, reducing incoming damage export var armor := 0 # calculates damage and send signal func get_hurt(damage: int) -> void: var final_damage := damage - armor emit_signal("hit_landed", final_damage) ``` Would be nice if somebody help me. 2 0 Feb. 17, 2024
Site is in BETA!found a bug?