The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

So I'm trying to make my player teleport to the place where the ender pearl hit.I'm doing this in 2d btw.

in Engine by (12 points)

1 Answer

+2 votes

connect a signal when the pearl collides, when the signal is triggered set the player's position to the pearl's position

by (454 points)
edited by

it returns a "invalid set index'position'{onbase: 'null instance') with value of type 'Vector2'."error when I try to run this code by connecting a signal to the pearl:

func _on_Area2D_body_entered(body):

well, I am teleporting but not in the area the pearl collided but after the pearl got thrown. What should I do?

on the pearl's script:

onready var player = get_node("player")

  func _on_Area2D_body_entered(body):
    if body.is_in_group("wall"):
      player.global_position = global_position

something like that with the queue_free() function the pearl should be deleted as well

I meant to say that I want my player to teleport to the point where the pearl collides. The pearl also disappears after it collides.

Umm... while using the corrected code, I'm not getting teleported towards the walls rather the walls are getting teleported towards me.

I edited the code again please see the last code that I wrote.

it returns "invalid set index'position'{onbase: 'null instance') with value of type 'Vector2'." error again.

that means it couldn't find the player node so you have to find the correct path, so for instance if your player is in the game node the path path would be


My player is in the player scene so I tried to use:


and I also tried to use:


and neither of those worked. So what am I doing wrong?

you have to reference the player's node not the player's scene that is different the node path in the scene is different from the scenes path in the project res:// is used for files system resources.

but how do I reference a player's node from another scene?

i advise you to watch tutorials or read books on godot because those are a lot of things to cover in the answers

yea you're right, I'll try to learn and figure something out. I'm a total beginner now so I can't really understand basic things. thank you for everything.

you're welcome

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.