Godot Version
Godot 4.6
Question
I trying to make a battle transition where when the player enters the Area2D node, it transtions into a the battle scene, and when the player clicks the run away button, there is an 85% chance the play can run away. I managed to get the transitions to work, but when I transition into the battle the player can still move around in the world. I tried to add this line of code ‘get_tree().paused = true’ but this would stop the enemy spawning in and the buttons stopped working. For my run away button I initially had it change the scene to the main game scene, but this would reset the player position and world. Is there a way to stop the player from moving, and then to allow it to move again from the same position in the world. If you need anything more just ask.
#My Battle transtion code#
extend Area2D
var battle = preload("res://Battle_scene/Battle.scn")
var battle_ui_scene = preload("res://battle_Animation_ui.tscn")
var Player = preload("res://player.tscn")
func _on_body_entered(body):
if body.is_in_group("Player"):
var BattleUI = battle_ui_scene.instantiate()
get_tree().current_scene.add_child(BattleUI)
var animation = BattleUI.get_node("AnimationPlayer")
animation.play("TransitionIn")
await get_tree().create_timer(1.5).timeout
var battleTemporary = battle.instantiate()
get_tree().current_scene.add_child(battleTemporary)
animation.play("TransitionOut")
#get_tree().paused = true #THIS STOPPED THE ENEMY FROM SPAWNING AND PREVENTS BUTTON FROM WORKING#
queue_free()
#My BattleUI code just for run button#
extends Control
var Inventory = preload("res://player_inventory.tscn")
var battle_ui_scene = preload("res://battle_Animation_ui.tscn")
var game_world = preload("res://game_world.scn")
var battle = preload("res://Battle_scene/Battle.scn")
func _on_run_button_pressed() -> void:
var fleeProb = randi_range(0,100)
if fleeProb <= 85:
var battle_ui_instance = battle_ui_scene.instantiate()
get_tree().current_scene.add_child(battle_ui_instance)
var animation = battle_ui_instance.get_node("AnimationPlayer")
animation.play("TransitionOut")
await get_tree().create_timer(1.5).timeout
get_tree().paused = false
get_tree().change_scene_to_file("res://main_game.tscn") #THIS RESETS THE WORLD#
battle_ui_instance.queue_free()