This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm trying to write a teleport script, how can I simply teleport PLayer to a position of a certain node?

I have this in my PLayer script:

func teleport_to(target_pos):
    position = target_pos

How do I invoke it in a keypress script? Right now there's a line using Groups, but it doesn't work

export (NodePath) var teleport_target = null

if Input.is_action_just_pressed("enter_door") and player_in_door == true:
    get_tree().call_group("Player", "teleport_to", get_node(teleport_target).position)

When I press that button there's an error:

Invalid type in a function 'get_node' in base Area2D (Teleport1):
cannot convert Argument from Nil to NodePath

Please help!

in Engine by (53 points)

The node Im trying to teleport it to is called Player, and its not working. Do I have it backwords?

https://docs.godotengine.org/en/stable/classes/class_node.html#class-node-method-get-node

get node is relative, if Player is not a direct child of the node you are at it won't work

oh that makes sense then. Is there a way to teleport to a node that's not a child?

Sure it is possible, you just have to find the Node.
get_node gets the node from anywhere. You just need to find it in the tree. i believe there is also a find_node method that allows you to search for a node by name. Check the documentation or other resources on how to do that.

ok ,thank you

Please log in or register to answer this question.

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.