Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cshenkan · Jun 29, 2018 at 07:13 PM · collidersdesign-patternsstrategy

Civ Like Game Handling Tile Interactions

I've been planning out a civ like strategy game which would uses hexes or tiles. For this type of game it seems to me that colliders are not really necessary since all movement and unit placement is handled by the game.

I'm looking for some guidance regarding how to handle checking for interactions between tiles and units. I understand this is pretty heavily dependent on how the game is set up and structured but if anyone can provide me with any tips or suggestions on approaching how to design it it'd be a tremendous help.

The way I've considered handling it would be just merely writing a method to check the unit's or tile's status and initiate combat or display the appropriate options depending on the type of tile/whether it's occupied/etc. One of the issues I for see in this approach is that it would lead a very large if-else tree or a large switch statement and I'm not sure how this will affect performance.

Any input would be appreciated!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hexagonius · Jun 29, 2018 at 07:34 PM

First of all a link to hexmaps:
Catlike coding hexmap tutorial

For the second part, thinking about large if else statements is already not the best approach. The first approach, thinking about the map as the representation (view) of the game state and logic (model), is a good idea. Check out the Mode-View-Controller pattern to get an idea how to keep visuals seperate from logic.
A little guidance example:
Think about unit selection of a tile. Since mouse input must be polled and in that be triggered by Unity callbacks, you'd need a MonoBehaviour as your InputManager. This Manager can direction these clicks to another class that is aware of all the tiles. It could then, since it is a hexmap, calculate which you clicked and return it. The result could then be passed into another class that knows the internals of a tile, like if there are units, gold, whatever. Here comes the tricky part with the if else. Depending on possibilities, there could just be an object reference to some occupant (gold, unit, building). if that is not null, you can then pass it depending on it's actual type to whatever class will handle it. So it's less if gold if unit if... but is it occupied, give me the occupant, otherwise do nothing (or pick this field as a destination for yet another class responsible for pathfinding if you have previously selected a unit to walk).
I could go on, but maybe that's giving you the right idea.
Quill18 has a veeeeerry long Tutorial where he explains very well how a MVP works and shows that while building a base building game, also using A* Pathfinding:
Quill18 Base Building Game Tutorial

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

89 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

physics.OverlapSphere colliders 1 Answer

Strategy Pattern with Monobehaviours 2 Answers

Colliding without gravity 2 Answers

Collider doesn't work always 1 Answer

Overcoming Mesh Colliders (car falls through street) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges