0
\$\begingroup\$

When an enemy dies in my game, it drops an item on the ground. Enemies may drop multiple items. Currently, the item will always drop a set distance directly below the origin of the enemy when it dies. Therefore, if multiple items are dropped, I only see the most recently dropped item on the ground. Moreover, each item has a UI label clamped to some offset distance above the item. As such, I only see the UI label of the "most recently" dropped item. Because every item dropped by an enemy drops at the same physical location, and because I haven't added code to deal with this kind of thing, the physical game objects overlap with each other and the UI labels of those items overlap with each other.

My question is pretty general. What are the best ways to modify my code such that

1) If multiple items are dropped, there will appear to be multiple game objects on the ground (Close enough to the origin)?

2) The UI labels attached to each item will appear as close as possible to that item without overlapping with the other items' UI labels?

I would appreciate direct assistance or references that deal with this kind of thing. Thanks.

\$\endgroup\$
  • \$\begingroup\$ Can you show us a screengrab of your game to ensure we understand your situation? I could see both tile-based and continuous coordinate solutions, for instance, depending on how your game is set up. \$\endgroup\$ – DMGregory Jun 18 '17 at 6:09
  • \$\begingroup\$ It's not on this PC so I cannot provide screenshots right now but I'll try to get around to it asap. FYI, it's a very simple 3d game. Items are spheres on the ground and UI images are attached to the top of them using WorldToScreenPoint. \$\endgroup\$ – embracethefuture Jun 18 '17 at 7:00
1
\$\begingroup\$

I would suggest you to keep track of the items that are going to fall when the enemy dies. And if there are more than one, set a little offset between the falling objects and moreover, I would choose an area which is right below the enemy's dead body, and randomly distribute the falling positions of the items in that little area to give it a more realistic look. Note: For this solution you need to check that randomly generated positions are not very close ones, in order to make the solution work.

\$\endgroup\$
  • \$\begingroup\$ Thanks, I went with something like what you suggested. dropPositionOffset = new Vector3(0f, originToGroundDistance, numItemsDropped * -2f + 2f); drop = Instantiate(itemPrefab, transform.position - dropPositionOffset, Quaternion.identity).gameObject; Didn't find the need to add randomness yet, but I'll look into that. By the way, what about items that drop from multiple enemies that are close together? Those still overlap. What's the best way to check if there are items nearby. Do I need every item to check all close enemies' item drop scripts? \$\endgroup\$ – embracethefuture Jun 20 '17 at 11:24
  • \$\begingroup\$ Since it is a choice which is quite dependant on user experience, if you send me a message with the screenshot of that moment (multiple items on the ground) I can help more easily. \$\endgroup\$ – Tolga Şen Jun 21 '17 at 12:30

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.