- Home /
How to calculate distance from ground
I am making a game with a teleportation mechanic like ender pearls in Minecraft. Here is the code for the teleportation -
private void Update()
{
if (shouldTel == true)
{
transform.position = new Vector2(telPoint.transform.position.x, telPoint.transform.position.y + 1);
shouldTel = false;
}
}
I am using a tilemap for my level design (my game is a 2D platformer). So now what happens is that if I throw a crystal on the ground, I teleport a bit high in the sky because of the offset of 1. And if I throw it at the side of an in-world block (About, 24 PPU) I teleport on top or at the side of the block. But if I throw it at the side of a wall more than 3 blocks high, I teleport inside the wall. Is there any easy way to calculate the distance to the top of the tilemap collider and store it in an int variable?
Your answer
Follow this Question
Related Questions
Make an Object teleport a Random distance away. 1 Answer
teleport an object three quarters of its distance with the player after a certain time 2 Answers
Finding the location of the tile in a tilemap nearest to the player 0 Answers
Tracking distance after Instantiate 2 Answers
Making a 2d "radar" for space game 2 Answers