I want to set the position of a KinematicBody2D to a x and y coordinate. For example, how to teleport a KinematicBody2D to (1500,-500)?
Thanks for answers!
Set it's global_position-property. Attach a script to your KinematicBody2D:
global_position.x = to
Then call this function like this teleport(Vector2(1500,-500)) from somewhere else in the script. If you want to trigger the teleportation from a script attached to a different node, you will need to first get the correct node with get_node().
Booth works, but this is a little bit better, because I have a function, which can be called from everywhere in the script.
From inside the node:
position = Vector2(x, y)
and from a different node:
TargetNode.position = Vector2(x,y)
Instead of just straight modifying values like that, you can also use functions to do it, like: