How to do tiled movement tht respects solid collision layer?

Get help using Construct 2

Post » Sun Feb 08, 2015 10:58 pm

I want my character to move on a grid. I've found two decent methods of doing this, as seen in this screenshot:

Image

Either I set an angle and 'move the character forward' as many pixels, or I use 'Set X' and 'Set Y'.

Obviously there's no reason to mix-and-match like this, just showing I've tried both.


The problem is that neither of them respect the 'solid' parts of my collision layer! So I have a ghostly player character just floating through walls.

There's gotta be a fairly simple/elegant solution to this...
B
6
S
1
G
1
Posts: 96
Reputation: 912

Post » Sun Feb 08, 2015 11:21 pm

You could use a tilemap, with tiles that equal the size of the player and throw a solid behaviour on it.
Then you can store the player tile position and use that to check vs collision.

So if
player.Tile_X = 5
player.Tile_Y = 5

And the player press Right key to move to the right, you can do a tilemap comparison, so:
Tilemap.compareTileAt Player.Tile_X + 1, Player.Tile_Y not equal 0 --- (If that is the tile you use as collision)
....If that is not the case, you just increase the Player.Tile_X by 1 and convert the Tile position to a pixel value position (standard X,Y)

And you can do that for up and down as well, just by increasing or decreasing the Tile_Y variable.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests