Hello! I'm beginner on Godot. I'm working in a prototype project to I learn while try to work on my final project.
I don't know how to make my Player teleport. I'm creating a "Resident Evil like" game to make the character travel from the scenes, but TOTALLY 2D.
Ok, I've tried to teleport my Player with two manners:
ONE. Putting my Player.tscn on the map scene and using Teleport.tscn as instanced node.
Result: ERROR
Screenshot:
* Teleport.gd:
extends Area2D
export (String) var mapa
export (Vector2) var coordenadas
export (String) var posicao
func _on_Teleport_body_entered(body):
get_tree().change_scene(mapa + ".tscn")
if coordenadas != null:
# !!!!! TELEPORT NOT WORKING >:( !!!!!
print($Player)
#$Player.position.x = coordenadas.x
#$Player.position.y = coordenadas.y
TWO. Creating Map.tscn to put my Player on a kind of glass and call the_map's scene_ with "add_child".
Result:
Screenshot:
* Map.gd:
extends Node2D
const MAP = "res://Cozinha A.tscn"
const POSITION = Vector2(100, 50)
func _ready():
teleport(MAP, POSITION, "up")
func teleport(tp_name, tp_position, tp_turn):
var map_name = preload(tp_name)
var map_position = POSITION
var map = map_name.instance()
var current_map = map_name
add_child(map)
$Player.set_position(POSITION)