Hi all!
I'm building a RPG editor for users to build their own roleplaying adventures.
You can place monsters on the map and consequently pick them up and drop them on other spots. The map is grid based and the monsters are positioned on a grid map, but they are taller than the tile grid, so let's say if a monster X is standing on grid location 3,3 an another monster Y is standing below that monster on grid location 3,4 monster Y will overlap monster X. Now if I'd pick up monster Y and place it above monster X at 3,2 it should be put behind monster X. And if monster Z would be standing at 3,1 monster Y in 3,2 should be in front monster Z at 3,1 and behind monster X at 3,3. I hope I made clear what I'm trying to do! I've been trying to solve this by storing the X grid coordinate and Y grid coordinate in each monster.
Here is a screenshot of the layering going wrong in my approach:
Please login to see this attachment.
My followed approach is: when putting down a monster, I would record the X,Y grid value and then look at 5 places above the monster and 5 places below and then run consequently:
- IF monster_X_grid is monster_select_X -5 then move to front
- IF monster_X_grid is monster_select_X -4 then move to front
- IF monster_X_grid is monster_select_X -3 then move to front
- IF monster_X_grid is monster_select_X -2 then move to front
- IF monster_X_grid is monster_select_X -1 then move to front
- Move monster_select_X to front
- IF monster_X_grid is monster_select_X +1 then move to front
- IF monster_X_grid is monster_select_X +2 then move to front
- IF monster_X_grid is monster_select_X +3 then move to front
- IF monster_X_grid is monster_select_X +4 then move to front
- IF monster_X_grid is monster_select_X +5 then move to front
I'm sure my code approach super messy and sadly it is also not working correctly. Some times it does, but often it does not. I can imagine layering of overlapping objects is a thing that is done all the time in games built with Fusion, so I'm sure there must be a better way! Any tips on how to adjust layering when objects are placed behind and in front of each other in a 3D view?
Thanks!
Hugo