Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Scavex |
So I have made an enemy that shoots bullets. The dead function gets called every time the bullets of type Area2D hit my player. His health is decreasing but when his health is 0 his Collision Shape isn’t getting disabled. The Particles get emitted when his health is 0 which means the collision shape should get disabled and his motion should also be zero. But I can control him even when his health bar is all red. This is my dead function :
func dead():
playerhp-=1
if playerhp<=0:
print("Player with 0 health")
is_dead==true
if emit == false:
$Particles2D.emitting = true
emit = true
$Sprite.play("PlayerDead")
motion=Vector2(0,0)
$CollisionShape2D.disabled = true
And this is the script for the Bullets that enemy is firing :
extends Area2D
const SPEED =300
var velocity = Vector2()
var direction=1
func _ready():
pass
func set_bullet_direction(dir):
direction = dir
if dir==-1:
$Sprite.flip_h=true
func _physics_process(delta):
velocity.x=SPEED*delta*direction
translate(velocity)
func _on_VisibilityNotifier2D_screen_exited() -> void:
queue_free()
func _on_Bullet_Advance_body_entered(body: Node) -> void:
if "Player" in body.name:
body.dead()
queue_free()
I can’t see any mistake. Maybe something different is impeding?
MaaaxiKing | 2020-06-18 14:38
Yes it’s frustrating because the function is actually working since "Player with 0 health " is getting printed once my player health reaches zero but strangely enough the playerhp is going below 0 to negative values which is confusing
Scavex | 2020-06-18 14:43