Check where my object will be able to fit on teleport
Hello, I am working on a 2D platformer, the player will be able to teleport where he is aiming over a defined distance (let's say maximum 10 meters). It's composite colliders 2d using a tilemap collider 2d for the platforms and a box collider 2d for the player.
I'd like to avoid the player ending up inside another collider and if there is really no place to fit the player at the end of the line between him and his wanted teleport destination, to go to the last possible place along this line. (check pictures for better understanding)
I'm guessing I should be using Raycasting for the first part, to check for collisions, but I'm not sure how to check if the collider could fit where it will end up and how to go back to the last possible position for it. (e.g., first screenshot)
Do you have any suggestions, and if possible examples? 

Your answer