Currently, I am trying to set up a kinemeticbody2d (I'll call it teleporter) with a collision2d as a child of the kinematicbody2d player. The plan is, this teleporter is supposed to always be in front of the player so that when they teleport, they can move to the teleporter. When this teleporter collides with a wall, it would stop so that the player can't teleport into/through walls, then when you move away from the wall, the teleporter would move back. This is my current code for it:
const speed = 5000
var velocity = Vector2.ZERO
var location = position
if location != position:
velocity = position.direction_to(location.position) * speed
velocity = move_and_slide(velocity)
Currently, all that happens is a "Invalid get index 'position' (on base: 'Vector2')." If anyone has any advice on how to get this working, or if there's a better way of setting up this sort of detection, I would greatly appreciate the advice.