7.7 C
New York
Tuesday, March 25, 2025

unity – Easy methods to plan the animation of a posh fight between two teams of models?


I am engaged on a turn-based ways recreation in Unity3D/C# during which gamers management Detachments composed of a number of Models. Every Detachment occupies one hex on a map, and will comprise as much as one every of Troops, Equipment, Specialist, and/or Chief Models, which transfer and combat as one. When two detachments combat, their Models all generate and resolve assaults, which can kill issues within the different Detachment.

The implementation of that is break up so that each one the game-mechanic logic for a fight is executed first, producing the outcomes of the fight, after which these outcomes are individually animated.

I’ve the underlying fight engine elements applied to my satisfaction: given two Detachments, it would make and resolve all of the assaults accurately in keeping with the foundations of the fight system, and it information the entire assaults made and their outcomes. The place I am caught is animating these ends in a manner that offers a participant legible visible suggestions on what occurred. (There’s a separate fight log that they’ll view, however I might just like the visuals to be the primary supply of suggestions.) It is not the precise animation that’s the downside, however sequencing the essential occasions to be animated. From my perspective, the complicating elements are these:

  • Troops could comprise as much as 20 particular person Troopers, however Equipment, Specialist, and Chief Models are single Troopers.
  • The assaults happen in as much as 4 phases (Ranged, Assault, Pike, Melee) relying on the Models concerned, however, importantly, in every section, assaults are made “concurrently.” That’s, every Trooper on both sides makes all of its assaults for that section, and solely after all of the assaults are resolved do any Troopers get marked killed.
  • A Unit that makes a number of assaults in a section could make them towards completely different goal Models. This is likely to be as a result of they killed off their first goal and had extra assaults remaining, or as a result of they’ve two completely different weapons which might be optimum to make use of towards completely different targets.

My first try and animate the fight was to take the record of assaults made and assign every to an idle Trooper mannequin, having it animate that assault solely after the goal of the assault was finished attacking. I had assumed this might be finished in a manner that ends in a series of kills: Trooper A1 is killed by D1, which is killed by A2, which is killed by D2, and many others., till the entire deadly assaults have been animated. In apply, my implementation created loops the place assaults had been assigned such that A1 is killed by D1, which is killed by A2, which is killed by D2, which is killed by A1. Loops like this are after all an issue, as a result of there is no such thing as a surviving Trooper who can finish the chain.

So the query I now face is: given lists of Unit-level assaults, how can these assaults be assigned to Trooper fashions and ordered such that there are not any loops of deadly assaults? I consider this downside boils right down to the development of a directed graph with no cycles greater than 2 edges lengthy (since I can deal with mutual-kills the place two troopers kill one another), however my graph concept shouldn’t be ok to make certain that that is attainable, or to determine an algorithm to perform it.

The next abstractions are nice, as I do not assume they detract from the suggestions that the animation would supply:

  • It doesn’t matter which Trooper in a Troops Unit is animated making an assault or being the goal of an assault.
  • Non-lethal assaults do not must be animated, solely deadly ones. The final Trooper in a Unit might be killed as quickly as all of that Unit’s deadly assaults have been animated, even when a few of its non-lethal assaults haven’t.
  • A Trooper might be animated making extra assaults than the sport mechanics would enable. That’s, a Trooper that per the foundations can solely make one assault might be animated making a number of, if that is what it takes to keep away from cyclicality.

Issues I might choose to not budge on:

  • Each killed Trooper needs to be animated being killed by an assault from the Unit that truly killed it, within the section that it was killed.
  • Every Trooper needs to be animated making assaults so as of section. It mustn’t animate a Pike assault earlier than a Ranged assault, for instance.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles