Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Scavex |
Hello guys I have made an enemy with this script :
extends KinematicBody2D
const GRAVITY =10
export(int) var SPEED =20
const FLOOR=Vector2(0,1)
var velocity=Vector2()
var direction=1
var is_dead=false
export(int) var hp=30
func _ready() -> void:
pass # Replace with function body.
func dead():
hp-=1
if hp<=0:
is_dead=true
velocity=Vector2(0,0)
$AnimatedSprite.play("Dead")
$CollisionShape2D.disabled=true
$Timer.start()
func _physics_process(delta):
if is_dead==false:
velocity.x=SPEED*direction*3
if hp<=15:
velocity.x=SPEED*direction*6
if direction == 1:
$AnimatedSprite.flip_h=false
else:
$AnimatedSprite.flip_h=true
$AnimatedSprite.play("Corona")
velocity.y+=GRAVITY
velocity=move_and_slide(velocity, FLOOR)
if is_on_wall():
direction=direction*-1
$RayCast2D.position.x*=-1
if $RayCast2D.is_colliding()==false:
direction=direction*-1
$RayCast2D.position.x*=-1
if get_slide_count()>0:
for i in range(get_slide_count()):
if "Player" in get_slide_collision(i).collider.name:
get_slide_collision(i).collider.dead()
func _on_Timer_timeout() -> void:
queue_free()
And I have made this powerup allowing my player to jump higher for 5 times :
extends Area2D
func _ready() -> void:
pass # Replace with function body.
func _on_Long_Jump_body_entered(body: Node) -> void:
if "Player" in body.name:
queue_free()
The code for the logic is this and is in Player Script :
func _on_Long_Jump_body_entered(body: Node) -> void:
JUMP_HEIGHT=-600
My question is that how can I actually make the powerup appear only when my enemy is dead. For example my enemy is of type KinematicBody2D and powerup is an Area2D. How can I make that area2D appear only when KinematicBody2D is dead ?