1
\$\begingroup\$

The context is an 3D engine with a 2.5D level format. Like a roller coaster tycoon level, with some other level features added, and layers removed. For example the tile functions have the following interface.

markTile([3, 5]);

This statement places a mark on the tile located at 3x5. This tile can be on top of a mountain or a cave, but different tiles on the same height can't exist, so the Z axis isn't needed. Internally everything is in 3D, but it isn't exposed to the interfaces since there can't be more than one tile at the same X, Y position.

Because the tile functions are 2D, units also store their positions in 2D.

markTile(unit.position); // place a mark where the unit is

There are also cases where knowing the Z of an unit is useful, but it is almost never about the tile or the placement position. For example it is useful to create a sprite or an exclamation mark on top of an unit, but that is done by using the Z from the tile and the height of the unit. That interface also uses an unit as the parameter, not a position, because multiple units can be on the same position unlike a tile.

placeExclamationMarkOnUnit(unitId);

Now, I am wondering, is there a need for the raycaster to even return the Z data in this setting? I can't think of a gameplay case. I can think of cases where the unit height is important, but none that would need to know the Z from the ray. I can also think of cases where I could want to place an effect on an exact position on the unit, but that can be done by just X and Y(floats, not ints) as well.

Thanks.

\$\endgroup\$
  • \$\begingroup\$ StackExchange is generally better at solving problems "I have issue X, what solution Y can solve it?" than it is at listing problems "I have a solution Y (getting the Z value of a tile), what problems X does it solve?" - if you haven't found a need for the Z value yet, would it suffice to tentatively assume it's not needed, and leave it out of your interface until & unless a demonstrated need arises? \$\endgroup\$ – DMGregory Mar 19 at 0:46
  • \$\begingroup\$ That is a good point, but it is also a considerable effort to refactor every related interface. I have used engines that defined inconsistent interfaces where I would receive some data from a function, modify it slightly, turn it into some other type, pass it along something else. I am trying to avoid that by defining as few unique interfaces as possible, but it also means refactoring the code is harder. I was hoping someone could be willing to share their experience if they have experienced such an use case, which would be considerably less of an effort for them. Is this an unreasonable ask? \$\endgroup\$ – Lacey Mar 19 at 1:14
  • \$\begingroup\$ I am also fine with not getting an absolute, definitive answer, and it is fine if I receive a "negative" answer too. An answer such as "I have looked into this in the past and I haven't found a significant case" is very much valuable to me. I am also fine if I get no answers, that would point to "this can't be a super common case, as no one pointed out anything. It could exist, but it is likely not very common". Perhaps these questions aren't worth as much in the sense there is no single absolute answer, but surely you can agree it is a valuable question? \$\endgroup\$ – Lacey Mar 19 at 1:18
  • \$\begingroup\$ It's not unreasonable, we just might not have good answers for you. Your game system might be used in ways that don't occur to our users, since we're not interacting with your framework in our daily work. It's entirely possible there are cases where Z is needed that we won't think of. Or there might be alternatives offered by your API of which we're unaware. So we're prone to give you both false positive and false negative errors, compared to testing your project with real users. \$\endgroup\$ – DMGregory Mar 19 at 1:20
  • \$\begingroup\$ I understand that. I am just looking for a mechanic or a visual effect that depends on this value to work well that I just couldn't think of, and I would be interested in learning about it. This style of engine by itself isn't the most common, so I understand it isn't going to be the most familiar thing for many people, but the level format is seen in similar forms in many RTS engines and it isn't really rare per se, in my opinion. And thank you for taking the time to discuss this and letting the question stay, I am very much grateful ^__^ \$\endgroup\$ – Lacey Mar 19 at 1:35
2
\$\begingroup\$

One example is overlapping objects, where you want to sort them by z value and act on them one at a time. Consider a system where pressing x over a trigger causes the player to perform some kin of interaction. If many of these are overlapping, and there's no priority set, you likely want the top most one. But what if some are disabled in terms of interaction, but not in terms of GameObject.SetActive(). Now you want the list of overlapping triggers (which unity doesn't guarentee is sorted by z value) then you want to sort them via z value (from front to back) and get the first one that is capable of interaction, or passes some set of conditions.

\$\endgroup\$
  • \$\begingroup\$ Sorry I can't upvote the answer as I lack the reputation. I will mark this as the answer after a few days if there are no better answers. This example is indeed valid in general, so don't take this as an argument against it. In this specific example, the raycaster contains the command which allows you to "remove" an entity from the "map". This is a cheap operation. This way, units can be "disabled". The raycaster also returns only the top-most unit. Is there an example where an unit other than the top-most is desired, and it can't be handled via "disable"? \$\endgroup\$ – Lacey Mar 19 at 17:22
  • \$\begingroup\$ I think that really depends on your game and the rules you implement down the line. I can answer with confidence that there probably exists a game with your requirements that would make use of the z value. However it's like asking someone if there's ever a scenario they need to learn calculus if they want to become a musician. I'm sure there's a scenario, but it's not likely to apply to any general case. \$\endgroup\$ – gjh33 Mar 19 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.