So, as the title says, I’m doing a Beat’em up ala Streets if Rage. The plan is, at some point, to have different attacks, a parry/dodge and a Grab (no button, just walk “into” an enemy).
I’ve seen people that do it creating an empty object (Attack Point) that floats in front of the character and use it as a a casting point to look for colliders,
Other people uses the whole boxcollider that represents the character to look for triggers; that would mean altering the collider in some animations (there are sprites that are larger than others, but could be worked around to make all sprite “equal”).
Also, I haven’t decided yet if the game will be un full 2D (with “fake” 3D effect) or not, but at the moment I’m working with 2D, no physics.
Rigth now I’m going with the first one, the casting point to test the simple attack mechanic. If someone around here has been there, I’d really apreciate the tips or advices. If there is a better (or easiest) way to do this, I’ll be gratefull.
Seems like the old 2D brawlers just did simple distance checks.
Something like this, pseudocode:
if(currentAnimationFrame == attackFrame) // like the frame when our fist is fully extended)
{
foreach(enemy)
{
if(enemy.position is in front of us and within range)
{
enemy.TakeDamage();
}
}
}
Your approach sounds fine. Rather than making other suggestions, like adding animation curves that specify how much power an attack animation has at various keyframes, I recommend you scour Universal Fighting Engine’s documentation. They’ve been fine-tuning this stuff for years, so you might as well give yourself a head start by learning from their experiences rather than having to discover them all over again. You don’t have to do things they way they do, but you can borrow concepts and familiarize yourself with pitfalls they’ve had to overcome.
I totally overlooked the UFE, but it makes sense to give it a look. I should be able to find some ideas about hitboxes, chain moves and linking animations.
Right now I have a simple code that idles, walks and attacks. I have some issues with the whole transition between states:
Idle has 2 frame animation and transitions to Walk with a boolean that catches kewboard input.
Walk has 3 frame animation that plays as long as a boolean is on true, if not reverts to Idle. Should I make the input something like “onKeyDown” event? I’m coding on the Updtae function as I have no physics.
I plan to use the Animator conditions (parameters, booleans, onTriggers, etc), but I fear that may “lag” the transitions. I’m in the right path?
I’ve been tweaking a bit. Now the idle->walk->idle transition run smooth and cool, but another issue arises with the Attack animation.
I have a trigger parameter that transitions from “any state” to “attack”; I catch the input with getButtonDown and set the trigger for the animation to star via code, then catch an event when animation ends to get back to Idle. It works, but it seems like the trigger for “start attack” sometimes does not work and makes the whole thing feel “laggy”.
While playing, click on your character and watch the live view of your animator controller in the Animator view. It might show you whether it’s lagging when setting the trigger or when transitioning to attack.
“Has Exit Time : Determines whether the transition’s condition can take effect at any time, or only during the state’s exit time.”
This is possibly what’s making your transitions look weird. If HasExitTime is checked for the transition from any state to attack, it can’t start the transition until the current state has reached a certain time in it’s execution.
isJump or isAttacking is probably true, which would prevent that code (SetTrigger, etc.) from running.
This suggestion skirts around the problem instead of addressing it, but why not allow the player to set the “attacked” trigger at any time, even while still attacking or jumping? If you set the attack state atomic, it won’t interrupt itself if the player mashes the attack button. This might make the controller feel more responsive, too.
p.s. - If you end up posting longer blocks of code, please help out your readers by using code tags.
The idea behind a flag for “isAttacking” is prevent the object form moving while attacking (the attack animation do not have translation); if you keep pressing forward while attacking, the sprite moves sliding while throwing a punch.
p.s - sorry about the code part, solved; won’t happen again
EDITED: found one thing that makes the game run smooth. I increased the speed of the “idle” animation (actually not an animation yet) and put all transitions from state to state (not Any State anymore). Now Attack responds better.