Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Trattles · Nov 08, 2014 at 07:53 PM · c#rtsmeleecombat

How to Instantiate a Combat Manager to handle attack order?

So In this game, when 2 enemy units collide, they enter melee combat. The game is RTSish, so any number of melee combats could be occurring simultaneously. When in combat, I want to ensure that units do not just hack away at each other, but rather that when one is attacking, the other "receives" the attack (in order to run a blocking animation etc.)

My idea here, is to have a "combat manager" that essentially contains a list of attacks. The manager would build this list based on unit attack speed, so that when a unit is ready to attack, it adds an action to the combat manager. Then the combat manager, pops the top action off the list, listens for it to resolve, then pops the next, and so on.

My question is, when two units run into each other, how do I handle instantiating an instance of this combat manager for that specific melee? I had though to call it on the units "EnterMelee" method, but how do I ensure that both units don't call a combat manager, and that they instead share one?

I'm writing this in c#, but i'm looking for more conceptual advice than straight code.

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 AlwaysSunny · Nov 08, 2014 at 03:53 PM

I like high-level managerial classes, so I'd make mine a singleton, and let it resolve Conflicts. Each agent entering conflict would signal the manager. The method arguments would include a reference to the agent and its combatant. If there's no conflict in the list between those two agents, create a new Conflict object.

A calls with (A,B);
Manager creates Conflict;
B calls with (B,A);
Conflict already exists so do nothing;

A loop on the manager runs to resolve active conflicts. The order-of-attack and other mechanics are thus separated from the lets-do-combat logic. The Conflict object could examine whatever logic necessary, have its own timers, whatever's needed.

Comment
Add comment · Show 2 · 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
avatar image Trattles · Nov 08, 2014 at 07:11 PM 0
Share

Doesn't that create a race condition? If a and b enter at the same time it would always spawn 2 instances right? so the situation where a spawns instance and then b joins would never work?

avatar image AlwaysSunny · Nov 08, 2014 at 10:29 PM 0
Share

Nothing ever happens "at the same time" in computer science! ;)

A triggers the manager to create a Conflict object representing (A,B) which is entered into the list. When B triggers the manager to create Conflict (B,A) immediately thereafter, all you must do is exa$$anonymous$$e existing conflicts prior to creating one to find that a conflict between these two already exists. B doesn't need to "join" - it's involved because A's call included it as an argument.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Melee Combat 1 Answer

Procedual Wall Generation 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 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