How do I calculate distance to tilemap?

Get help using Construct 2

Post » 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)))

Image
B
30
S
14
G
2
Posts: 28
Reputation: 3,341

Post » 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 :

Image

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

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
292
S
115
G
96
Posts: 7,293
Reputation: 70,769

Post » 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

Image

here is the code I ended up with
Image

The effect remind me so much captain comic :p
https://www.dropbox.com/s/fhlpe6btey5rv6q/teleport%20simple.capx?dl=0
B
30
S
14
G
2
Posts: 28
Reputation: 3,341


Return to How do I....?

Who is online

Users browsing this forum: MassimoF, Microbex and 20 guests