Now I understand that many people have asked this question, but I don’t think that what I have in mind can be applied to those. I have a bit of a complicated idea and I don’t know exactly how to implement it. I’m not sure how to script it so that’s why I put it here.
Basically, I want to implement a system that whenever you go into a certain range of an enemy, time essentially slows. When it does there are three combo options for attacks, each with different levels of efficiency depending on the attack. So for example an enemy is coming at you with a thrust. There are three combos that appear on your screen. You have to complete one of the combos within a certain amount of time, and then the character will preform the action. But, for a random example, let’s say you use the least efficient combo, one of the three options, against the thrust. Then you will preform an action, but you will be hit by the sword. It seems complicated, and I’m looking for a way to do this. Any ideas?
.When a character targets you & attacks you trigger an engage event.
.The event slows time & presents the combos.
. You track the input. Comparing against a list of valid combos
. If a combo is complete you run its code for the response.
.The response can send an event to the attacker to let them know how to react
In terms of code you would want an base class for an attack this will get over ridden by new attack definitions, when their combo is input these will handle controlling the player and the attacker if they need to perform an action aswell.
You will want another class for holding a list of inputs that are needed to trigger the combo & a reference to the attack it will trigger.
Then a class for handling a clash between two characters this will slow time/display the prompts/activate the attack.
Awesome, thank you. So when you’re sending an event to the attacker would it be like an if statement? Something like, if (blank combo) Is run, do (blank) attack?
Sorry, when I say send an event I meant using an event system. Unity has its own that you can use or you can create your own (there are a few tutorials that you can find on google). Generally an event system is just a class that holds a list of delegates, other classes will add & remove themselves from the event system & it allows classes to interact with each other without having to know what the other class is.
What you seem to do sounds like two object interacting without the need for others to be involved. Why would you want to use an event system for that? I solve a similar task in my game by having the object interact with each other. An event system seems somewhat overkill for that.
It can be done plenty of ways, but personally I would have something telling both objects what to do. That way it can expanded to handle more than 2 objects interacting, the point of an event system is also to reduce coupling between classes so this way if a specific enemy has a special way to react it can easily be implemented without too much hassle.
Interesting. I am developing under a more sort of natural guidance system. Ie, fighter sees zombie and reacts to zombie with a move. Hence, interaction via raycast and collision, no events. But, for instance, an earthquake or rainstorm effects all actors in the scene, so, event system.
I also base all mobs on the same ancestor class, overriding functions when needed, but they do all react in the same fashion. Mind you, it’s quite experimental and meant as a study into how it all works.
If it was normal dynamic combat stuff, I would probably approach it differently. Since this is essentially quick time events & two actors having to fluidly do stuff together I think something else pulling the strings is a good way of keeping things in sync.
Dont get me wrong I’d have some polymorphism still in there, but due to how scripting languages work events are a nice way of avoiding having a list of components to inform that something has just happened.
I think I might use events in such a case. I do have the time slow down mechanic in a similar fashion, a command wheel pops up, time slows down and the player needs to select an action before time is stopped completely. But, that’s not quicktime and only affects the player.
I never really considered using events before in unity, they seem quite cumbersome for some reason. I tried a few times, but never followed through.