# How do I calculate distance to tilemap?

Get help using Construct 2

### » Fri Mar 31, 2017 2:13 am

Is it possible to calculate the distance of an object to tilemap
I am trying to teleport the player but I don't want his new position to be inside the ground

this is what i'm using for the teleport function:

when btn pressed -->
if palyer mirrored ---> set player x to self.x-50
else --> set player x to self.x+50

What I'm trying to do is to add something like this

when btn pressed -->
if palyer mirrored ---> set player x to self.x-(min(50,distance( player,tile edge)))
else --> set player x to self.x+(min(50,distance( player,tile edge)))

B
39
S
18
G
4
Posts: 44
Reputation: 5,007

### » Fri Mar 31, 2017 3:33 am

You should actually check if 50 pixels from player's X position is belonging to a tile.

To do so I'd suggest :

This works for when the player is to the left of the tilemap.
Invert the check for when the player is to the right, have the correct check depending on the direction the player is going.
New to Construct ? Where to start

Please attach a capx to any help request or bug report !
Moderator
B
312
S
129
G
101
Posts: 7,432
Reputation: 75,388

### » Fri Mar 31, 2017 4:14 pm

Beautiful thank you so much @Kyatric

Just want to add you code will work if the collision box of the tile is set to bounding box.

If the collision box is like the picture bellow you will need to add that part for the Y position, for my situation my player is taller that the tile so I set it up to BBoxTop

here is the code I ended up with

The effect remind me so much captain comic :p
https://www.dropbox.com/s/fhlpe6btey5rv6q/teleport%20simple.capx?dl=0
B
39
S
18
G
4
Posts: 44
Reputation: 5,007

Return to How do I....?

### Who is online

Users browsing this forum: Exabot [Bot] and 15 guests