Emulating depth & Z-fighting

Get help using Construct 2

Post » Thu Sep 06, 2012 6:53 pm

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.Hasuak2012-09-06 19:01:34
B
21
S
7
G
4
Posts: 233
Reputation: 3,474

Post » Thu Sep 06, 2012 7:21 pm

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.
TELLES08082012-09-06 19:29:02
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Thu Sep 06, 2012 7:45 pm

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 ;)
B
21
S
7
G
4
Posts: 233
Reputation: 3,474

Post » Thu Sep 06, 2012 8:01 pm

[QUOTE=Hasuak] 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 ;)[/QUOTE]

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

^^TELLES08082012-09-06 20:05:24
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824

Post » Thu Sep 06, 2012 8:24 pm

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 examplelinkman20042012-09-06 20:24:49
Moderator
B
113
S
41
G
20
Posts: 1,586
Reputation: 19,126

Post » Thu Sep 06, 2012 8:33 pm

And you still needing to avoid sorting the entirely canvas, because of performance issues: Post about it here
Image
B
108
S
24
G
18
Posts: 1,373
Reputation: 22,824


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests