How do I create rebounds on obstacles in a tile-based game?

Not favoritedFavorited Favorited 0 favourites
  • 4 posts
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • Hi everyone! How would you go about creating a rebound behavior in a tile-based game? Meaning my character could be sent in 8 directions with a press of a button, will always move on the tiles (like a chess piece), and also rebound on obstacles (wall tiles for examples).

    Here is an example of a move I'd like to make possible with those constraints :

    My character is "launched" in a upper-left diagonal, with a force of 6. Meaning it will move on 6 tiles before stopping. So as you can see with the yellow line, it will rebound on vertical and horizontal walls, and also on the final angle (where the rebound just pushes it back on the same tile, maybe that's not a correct behaviour, but it's not important for now).

    I'd like to have an acceleration and deceleration behaviour too. Also, the character will damage any enemy encountered (and rebound off of them, too).

    For now, I'm using a moveto behaviour and I kind of succeeded to make the character go in the right directions ; but it seems the rebound thing can be done in a loooot of different ways (bullet behaviour ? Calculate angles ? Calculate beforehand the number of tiles to be travelled ? etc.) and I was wondering if any of you had a good idea of the best way to proceed.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sounds pretty straightforward. You can know when to bounce depending on the direction you want to move and the tiles in that direction.

    Like if moving to the right, check one tile to the right first. If it’s a wall then just set the direction to left.

    Same can be done for all directions. Although it should be possible to simplify it down.

  • I focused on the bounce portion while moving only on the grid here.

    dropbox.com/scl/fi/t7bbsf3u9989nyxuzw2fs/tilemap_bounce_grid.c3p

    This one moves smoothly between grid positions with an emphasis on smooth and robust collisions. AKA. Collisions are never missed.

    dropbox.com/scl/fi/p3w0tzuxk7phzpdl5s9je/tilemap_bounce_grid_smooth.c3p

    Might provide some ideas.

    For what you want you could count how many tiles it moved before reversing the angle of motion.

    You could use any other movement behavior to move and bounce the objects too, but there is a inaccuracy that will come up.

  • Wow, thanks a lot for those two projects !

    It works very fine (even though I must admit I have a hard time understanding everything in the code, I think I managed to get a grasp of it), and I love how it follows every tile very precisely, but it might be limited in my usecase. I'll elaborate further, as I really appreciate how simple the code is and I hope I can achieve the same simplicity for my needs.

    First, I should have stated I'm actually not using the tilemap system in this project. I realize saying this was a "tile-based" game was silly of me, as itseems to imply the project is using tilemaps.

    I'll actually use sprites, because of animation needs, and also because monsters and other type of objects will have the same effect as walls on the player (rebounds, etc.) - plus other behaviours (pathfinding, etc.); from my understanding, this is not possible with tilemaps. For these reasons, I'm trying to achieve this rebound behaviour without using tilemaps.

    I tried playing with the bullet behaviour or 8directions, but it does not seem to be the right way to go about it. Notably because I need to have a "preview" of the movement before validating ; something similar to what one can find in golf games, where a dotted line is drawn from the ball and emulates every rebound the ball will make on obstacles in its way (ironically, no construct tutorial I could find about golf games had this feature). I'll need to display a similar preview, with every tile to-be-crossed numbered (to use the picture I shared in my first post, imagine every tile crossed would be numbered from 1 to 6, indicating to the player what path it will go, what rebound will be executed, and where it will end).

    For now, I managed to have a system where I can calculate on which tile the player will end in every 8 directions, but without any rebound ; meaning it will only move until it reaches a wall (I'm using those big purple lines you can see in the image to achieve this, but I feel it's not the right way to go about this).

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