How do I calculate distance to tilemap?

0 favourites
  • 3 posts
From the Asset Store
Enchanted Forest & Cave 16x16 Tilemap with Environment Sprites
  • 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)))

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)