|
|
|
|
Reply From: |
bloodsign |
As you said, when the bat’s collider hits the grass collider, it would throw an error, because
You see on your bat script:
func onHurtboxareaentered(area):
knockback = area.knockback_vector * 120
The area in that instance would be the grass’s collider. The area entered function of your bat calls knockback_vector, where it doesn’t exist in your grass’s script.
grass.gd
extends Node2D
func grassEfect():
var Grasscut = load("res://World/Grasscut.tscn")
var grasscut = Grasscut.instance()
var world = get_tree().current_scene
world.add_child(grasscut)
grasscut.global_position = global_position
func onHurtboxareaentered(area):
print(area.name)
grassEfect()
queue_free()
It works fine when the sword hit box’s area collider hits the bat simply because knockback_vector exists in the swords hit box’s script:
extends Area2D
var knockback_vector = Vector2.ZERO
There are several ways to fix this, first would be to separate the hurtbox of your sword and bat in to their own layer. Say we have the following layers:
Layer 1(world):
Layer 2(player):
Layer 3(playerHurtBox):
Layer 4(enemy):
Layer 5(enemyHurtBox):
and Masks
Mask 1(world):
Mask 2(player):
Mask 3(playerHurtBox):
Mask 4(enemy):
Mask 5(enemyHurtBox):
you could put your grass on the 1st Layer, and remove it from the any Mask Layer.
Layer 1(world): : Grass
This means that the grass is on layer 1 and it’s not looking in any other Layer(Masks)
Of course, assuming your Grass can be destroyed or attacked. Then if your grass has a HurtBox, you put it in to:
Layer 5(enemyHurtBox): GrassHurtBox
And remove the Grass HurtBox, from any other Masks or Layers.
Then on your bat’s HURTBOX mask and layers.
Layer 5(enemyHurtBox): BatHurtBox
This means that the Bat’s hurtbox(not the bat itself-assuming the bat and it’s hurtbox is separate nodes) layer is only on the Layer 5(enemyHurtBox) only. this should ignore any other colliders not in those mask layer
Then you put the sword hitbox mask/layer into
Mask 5(enemyHurtBox): Sword HitBox
Which means, the playerHitBox will only look for objects/colliders in the Layer 5(Mask: Enemy). And it won’t need to appear in any other layer, because the sword hit box only purpose is to interact with enemyHurtBox colliders or colliders found in that Layer, including the grass.
TDLR: Make’s sure your Grass HurtBox and Bat HurtBax, should not have any MASK layer turned on and should only be on their Hurt Layer.
Thanks for your answer, but… it did’nt work, i have already set the layers and masks as you said, but the bug continues, and its pretty weird because Heartbeast did’nt had this problem in his project, and there are several people with this same issue.
adrinx | 2021-02-22 22:54
Hmm, you are following heartbeast tutorial right? could you post your projecgt zip, I could take a look at it.
bloodsign | 2021-02-23 08:43