#How to change the player's position in another scene?

16 messages · Page 1 of 1 (latest)

lost hemlock
#
extends Area2D

@onready var PLAYER: PackedScene = preload("res://scenes/player/player.tscn")
var player_ref = null
func _process(_delta) -> void:
    if player_ref != null:
        if Input.is_action_just_pressed("select"):
            kill_enemy()


func _on_body_entered(body) -> void:
    if body.name == "player" and body.is_in_group("player"):
        player_ref = body


func _on_body_exited(body) -> void:
    if body.name == "player" and body.is_in_group("player"):
        player_ref = null



func kill_enemy() -> void:
    #Here I want to "select my player" and set his position to the center of this "area2d" scene
    pass
#

I would be grateful if someone can help me

#

OBS: is a topdown shooter (copy of hotline miami)

leaden root
#

You already have a reference to the player when player_ref is not null. So, in kill_enemy(), you can set player_ref.global_position = global_position.

lost hemlock
#

I have a timer in another scene that runs, when I go to the center, I want to stop that timer, how do I do that? I have to have a reference to that timer somehow and stop it, but how?

lost hemlock
#

i need to stop this

#

in the other scene

#

how do I do this?

hushed harness
#

Is the other scene the area 2d? If so you can do something like.

Player.up_timer.stop()

limber flint
#

I would have a signal in an auto-loaded script that all the enemies can connect to and stop the timer. And when the player reaches the center you can emit that signal.

#

is better than trying to have multiple node referencing each other

lost hemlock
#

I have an "area2d" scene and an "enemy" scene which is a characterbody2d, I need to stop the enemy timer in the area2d script