Emulating depth & Z-fighting

0 favourites
  • 6 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • So I finally decided to restart my fighting game. I've begun working on 8-directional controls like in Final Fight, Streets of Rage, etc.

    My problem is that I can't figure how to make enemies move behind another when they move "farther" from each other. By farther, I mean higher on Y-axis. I tried making a check like so:

    every tick

    Enemy.Y is greater than Enemy.Y

    Move to bottom of layer

    Doesn't sound very logical, especially when working with masses of enemies. Whenever enemy passes another on Y-axis, it's instantly sent behind the entire crowd. I'm not sure if this is even possible to fix without serious scripting, but any help would be appreciated.

    Another thing. How do I prevent z-fighting? I mean, the enemies try to align themselves with my Y-axis to attack. This causes the crowd to start "flashing" because they are overlapping each other.

    Thanks in advance.

  • I always use the same system as "Castle Crashers" and "Final Fighter", and any hack and slash game, by doing a simple 8 ways behavior on a shadow, instead of the player, so, the player instance is a simple sprite, and the real player is the shadow. When the player jump, it check it's Z from the shadow. Simple, efficient and large used on the game industry.

    You can also detect the damage by checking the collisions on the player sprite, leave the shadow for movement purposes.

    Edited:

    I think my explain was not so clear to understand. Let's try again.

    • Make a shadow in one instance, also, it can be a invisible object;
    • Make the player instance, place it over the shadow and update its coordinates relatively to the shadow.
    • Instead of making the player really jump, make it jump only relatively to the shadow. So can do the jump using math or using the platform behavior, pinning a solid to the shadow (it's not the best practice).
    • Any other things like the damage masks, collision masks (with other objects and not with the scenario X and Y limits) you'll pin on the player, not on the shadow, but the collision masks, you'll pin to the shadow, so, your player will not be able to walk out the scenario limits.

    If you have a CAPX to share, we can work on it and may help better than an explain.

  • Oh, my. I've never thought about that shadow thing. I need to check it out tomorrow when I have time. Thank you so much.

    Yet you didn't answer my question. I was talking about the walking enemies that overlap each other and doesn't go behind others when walking higher (farther) on the level. I just realized that whenever 8-directional object moves, it comes on top of the layer. Or so it seems. I'm not completely sure, since it could also be the action that I made for player's depth. I can make the enemy go in front or behind player sprite, but not other enemies.

    I can't really share my CAPX because it's full of graphics, test stuff, debugging etc. Pre rendered 3D stuff with lots of frames ;)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh, my. I've never thought about that shadow thing. I need to check it out tomorrow when I have time. Thank you so much.

    Yet you didn't answer my question. I was talking about the walking enemies that overlap each other and doesn't go behind others when walking higher (farther) on the level. I just realized that whenever 8-directional object moves, it comes on top of the layer. Or so it seems. I'm not completely sure, since it could also be the action that I made for player's depth. I can make the enemy go in front or behind player sprite, but not other enemies.

    I can't really share my CAPX because it's full of graphics, test stuff, debugging etc. Pre rendered 3D stuff with lots of frames ;)

    If your shadow is placed for enemies too, they will not be able to overlap each other, by checking their shadow.Y and collision polygons ^^

    Read more here: http://www.scirra.com/forum/rpg-games-and-the-overlapping-issues_topic51274.html?KW=rpg

    Also, you can know what enemy is behind each other by checking their ID. You can easily make an ID as an instance variable on creating or on placing the enemies on the Canvas (this way, just fill the ID on the instance right after placing them)

    Needing to know more about how to know what shadow is hitting with what shadow, you can check this little talk, it's a plus and you'll need it on the future: http://www.scirra.com/tutorials/361/understanding-uid-iid-health-of-enemies-and-rocket-smoke-trail

    ^^

  • Loop through the objects you want to sort using For Each(ordered) in descending order with the Y position of the sprite as the expression to evaluate, then send the object to the back of the layer. The objects will be iterated through from bottom to top and sent to the bottom in that order, so object's with a lower Y value - and higher on the screen - will end up in back.

    CAPX example

  • And you still needing to avoid sorting the entirely canvas, because of performance issues: Post about it here

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