Reputation: 11
`hello there first when i write my code that i want it to send the player from area 1 to area 2 or to another position it is dose not work i get many problem sometimes the said the
``
` E 0:00:17.512 get_node: (Node not found: "Player" (relative to "/root/Root/Area2D").)
<C++ Error> Method failed. Returning: nullptr
<C++ Source> scene/main/node.cpp:1465 @ get_node()
<Stack Trace> Area2D.gd:7 @ _on_Area2D_body_entered()
or errors like that that saying the player is not relative or not found
my code is like this
extends Node2D
var new_position = Vector2(-238, -379)
func _on_Area2D_body_entered(body):
if body.name == "Player":
$Player.set_position(`new_position`)`
``
so if there another way to send player from area 1 to area 2 or from position to another one please tell me and with all my thank full for any helps i get `
Upvotes: 0
Views: 135
Reputation: 40315
Is the player a child of the area? No it isn't. Thus the following does not work: $Player
.
You are being given the object that entered the area, it is body
. Freaking use it.
func _on_Area2D_body_entered(body):
if body.name == "Player":
body.position = new_position
Upvotes: 0