![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | Scavex |
Hello guys I wanted to know that how can I actually make a portal appear or function only when the boss dies. For example in my case I have a boss who the player can skip and go to portal to reach the next level and that’s not what I intend. I want the player to defeat he boss and only then he can use the portal.
Here’s the Portal Script :
extends Area2D
export(String,FILE,"*.tscn")var TargetScene
func _ready() -> void:
pass
func _on_ChangeStage_body_entered(body: Node) -> void:
if "Player" in body.name:
get_tree().change_scene(TargetScene)
Here is the Boss Script :
extends KinematicBody2D
const GRAVITY =10
export(int) var SPEED =20
const FLOOR=Vector2(0,1)
var velocity=Vector2()
export(String,FILE,"*.tscn")var TargetScene
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()
func _on_Long_Jump_body_entered(body: Node) -> void:
queue_free()
I tried doing various things and got error every single time.