How do I prevent positioning errors in gridlike movement?

From the Asset Store
Run and Jump in 3 Dimensions! Take your platformer to the next level!
  • Hello,

    I am working on an oldschool rpg that uses grid-like movement found in old roguelike games like Moria or Dwarf Fortress in which the player moves one tile at a time and you don't actually see an animation or sliding effect. I am posting a screenshot of my event sheet as well as the project as it is because there are two major problems with it when I test the movement out.

    1. When the player moves between a wall on the right to a wall on the left, the player icon is shifted up few pixels instead of staying aligning horizontally. I notice when the player hits a wall that doesn't continue downwards, it will start to shift as well for some reason.

    2. The player will not move into space that are as large as the player icon.

    I will point out that the player origin point is at 0,0 and the tiles and player are all 16 x 16 pixels and the tileset has the solid behavior. I've experimented with trying to make overlaying collision box objects that are the exact size of all the tiles and turning the tile collision off on the map and the same problems occur.

    Here is the project as it is with only the movement so you can see what I am talking about and below is the event-sheet along with properties of the player.

  • I don't really understand your code. You have so many events for such basic task. And half of these events are running on every tick, which is not great for performance..

    Why don't you simply check if player is overlapping an obstacle at offset?

    Say, you have a tilemap of obstacles, you can do this:

    On A pressed
    Player is NOT overlapping Tilemap at offset x=-16
    	player move left
    
    On D pressed
    Player is NOT overlapping Tilemap at offset x=16
    	player move right
    
    etc.
    
  • I don't really understand your code. You have so many events for such basic task. And half of these events are running on every tick, which is not great for performance..

    Why don't you simply check if player is overlapping an obstacle at offset?

    Say, you have a tilemap of obstacles, you can do this:

    > On A pressed
    Player is NOT overlapping Tilemap at offset x=-16
    	player move left
    
    On D pressed
    Player is NOT overlapping Tilemap at offset x=16
    	player move right
    
    etc.
    

    The ticks were something I was experimenting with to try to avoid the problem but I can probably do away with them. The Player is NOT overlapping tilemap at offset seems like it could work but I am uncertain how to set it to "NOT Overlapping" when I try to use it. When I try to add it as a condition it only gives the option to check if it is overlapping.

    I'm posting a version of the events without the tick events so you can get a better idea of how I'm getting the player icon to move. I'll point out that I don't want the player icon to actually be seen moving, but rather moved over a space sort of on a grid-like board like old ascii games which is why I'm using the change position thing. somehow it's being shifted out of place though when it moves.

  • I still don't know what collide_tile is on your screenshot. If it's a sprite object and you have lots of them, then you can't compare coordinates like that. You need to pick the correct instance first.

    uncertain how to set it to "NOT Overlapping"

    You need to add "Is overlapping" condition, then right-click and choose "Invert". It will become "Is Not overlapping"

  • I still don't know what collide_tile is on your screenshot. If it's a sprite object and you have lots of them, then you can't compare coordinates like that. You need to pick the correct instance first.

    > uncertain how to set it to "NOT Overlapping"

    You need to add "Is overlapping" condition, then right-click and choose "Invert". It will become "Is Not overlapping"

    The collide tile is what I named the tilemap that contains the layer of tiles block the player.

    I tried what you mentioned but for some reason the player doesn't move at all now, im not sure if the expression was incorrect. I tried making the tilemap not solid and using a layer of invisible walls that went over it to see if that would work but the player still doesn't move.

    This is what I minimized the event sheet down to.

    edit: I removed the top event that relocates the player to 128 x 128 and the player can move roughly 3 squares in either direction before it gets stuck again unless I move backwards from that spot.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It's hard to tell what can be wrong without seeing your capx file.

    "walkable" tiles on your tilemap should be empty (not set).

  • Here's the .capx with the event sheet i used minus the relocate event. The walkable tiles should be empty on that sheet.

  • Offsets should be in relative coordinates - (16,0). Not absolute like (Self.x+16, Self.y)

    Also, make the collision polygon on Player sprite 1px smaller from all sides.

  • That works just about right, im having a few problems getting stuck in certain tiles but I think I just need to play with the collision polygon some more.

    Thank you.

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