One thing you could do is add a RayCast2D
node to your KinematicBody2D
player node that is pointing down, and extends a reasonably long distance as to ensure it will always reach to the bottom of the screen.
Then, let's say you call a _die()
function when you want to move your player:
func _die():
var closest_platform = $RayCast2D.get_collider() # could be null
if closest_platform:
# use `closest_platform.position` to move
# your player where you want it
You want to be sure to enable
the RayCast2D
node, and under the "collisions" option, make sure "Areas" is checked. You may also want to uncheck "Bodies", so that if there are other entities that are bodies (enemies, etc), it doesn't return those instead, especially if all your platforms are definitely Area2D
's.
