I’m getting an issue with my enemies still checking others even if it’s disabled, the get_overlapping_areas() function in my Move() function still can get disabled enemies. When I kill an enemy, it’ll set the collisionShape to disable and also the process mode and I set it back to enable when needed, please help, is this an Engine bug?
This is my Enemy.gd
func Move(delta):
if(Global.world.localPlayer != null):
if(currentHealth > 0):
#Push other enenmies without using RigidBody, the get_overlapping_areas is getting disabled Collision, don't know why
for i in get_overlapping_areas():
if i.collision_layer == 2:
if speed == i.speed and global_position.y > i.global_position.y:
var direc = global_position - i.global_position
global_position += direc.normalized() * delta * speed
break
direction = Global.world.localPlayer.global_position - global_position
if (direction.length() > attackRange):
global_position += direction.normalized() * delta * speed
if(direction.length() > attackRange and aniTree["parameters/conditions/run"] == false):
aniTree["parameters/conditions/die"] = false
aniTree["parameters/conditions/run"] = true
aniTree["parameters/conditions/attack"] = false
elif(direction.length() <= attackRange and aniTree["parameters/conditions/attack"] == false):
aniTree["parameters/conditions/die"] = false
aniTree["parameters/conditions/run"] = false
aniTree["parameters/conditions/attack"] = true
if(direction.normalized().x > 0 and $Sprite2D.flip_h != false):
$Sprite2D.flip_h = false
elif(direction.normalized().x < 0 and $Sprite2D.flip_h != true):
$Sprite2D.flip_h = true
func DamageObject(damage, knockbackStrength : float):
currentHealth -= damage
if currentHealth > 0:
if knockbackStrength > 0:
knockback(knockbackStrength)
$Sprite2D.material.set_shader_parameter("hit_opacity", 100.0)
timer.start()
elif(currentHealth <= 0 and aniTree["parameters/conditions/die"] == false):
$Sprite2D.material.set_shader_parameter("canFlash", false)
var tween : Tween = get_tree().create_tween()
direction = Global.world.localPlayer.global_position.direction_to(self.global_position)
tween.parallel().tween_property(self, "global_position", global_position + (direction * 50), 0.4)
tween.parallel().tween_property($Sprite2D, "modulate", Color.TRANSPARENT, 0.4)
Global.world.consumablePool.CreateConsumable(global_position, 1)
tween.tween_callback(DisableObject)
func DisableObject():
Global.world.enemySpawner.enemyOnMap -= 1
if Global.world.monstersKilled.has(GlobalEnums.EnemyName.keys()[enemyName]):
Global.world.monstersKilled[GlobalEnums.EnemyName.keys()[enemyName]] += 1
else:
Global.world.monstersKilled[GlobalEnums.EnemyName.keys()[enemyName]] = 1
$CollisionShape2D.call_deferred("set_disabled", true)
process_mode = Node.PROCESS_MODE_DISABLED
visible = false
This is how i spawn my enemies:
func CreateEnemy(type : GlobalEnums.EnemyName, initPosition : Vector2):
#Get disabled enemy
var ref : Enemy = poolList[GlobalEnums.EnemyName.keys()[type]].GetDisabledPoolingObject()
ref.process_mode = Node.PROCESS_MODE_INHERIT
ref.visible = true
ref.currentHealth = ref.maxHealth + monstersHealthIncreased
ref.global_position = initPosition
ref.ResetState()
enemyOnMap += 1