Recoil not working on continuous attack

hoodust

Member
For my melee weapon I set the Use item ability to "Button Down Continuous" and combined with Wait For Animation Event checked on Use Event and Use Complete Event the player can hold down attack to keep attacking. However if I hit something with the RecoilObject component while attacking continuously, the attacks are sped up considerably (maybe 3x as fast) for some reason, and the recoil animation (Slot0ItemSubstateIndex = 20) is getting overwritten with 2 or 3 (depending on combo attack) before the recoil animation can play.

Single strikes (with just a button tap) recoil as expected.

Also, is there another way to cause recoil en masse besides manually adding the RecoilObject component to everything? It seems like a good use for the surface system, or even better a layer mask... since you most likely want recoils to occur when hitting everything that isn't in the Enemy layer.

If it helps, my weapon is based on the sword implementation and the demo animator.
 
Can you post a video of what you are seeing?

First I show the regular attack (works great, single strikes or continuous), then hitting a RecoilObject with single strikes (animation plays as it should, looks good), then I hold down the attack button and she wails on it like crazy.
 
Last edited:
Also because of this the character can get "stuck" sometimes, and not be able to attack anymore. The Wait For Animation Event checkboxes solved this for regular attacks, but for some reason the recoil module ignores this and just sets the substate index with 2 or 3 (or 4 if enabled) almost immediately, causing the way too rapid attack speed.
 
Have you tried looking at the animator to determine what state it is going into? The built in animator controller wasn't designed for this situation which is also likely why it is getting stuck.
 
I have, it's going straight to the next attack (not even letting it play out all the way like if it doesn't hit a recoil). But I can't find a way to force it via the animator, because it seems the substate index is what is forcing the animator. I tried removing transitions to the other attacks from each recoil state, and forcing "Has End Time" on the recoil transitions, but the substate index seems to override all of it. It never even goes to the recoil state/animation (or if it does it goes back to the next attack so fast you can't tell).
 
Actually you can see the transition from one attack to the next attack, so it's never even getting substate id 20 for recoil (unless doing a single strike).
 
Last edited:
With the animator moving so quickly it's hard to see exactly what is occurring, but you can also log the animator item parameters to the console which will help you narrow down what is being set. From there you can adjust the animator to fit those conditions.
 
It logs just what it looks like in the animator, and explains why I can't fix it with the animator.

1688152260390.png

During continuous attacking, it never fires recoil substate 20, until you let go of attack and the last one will recoil.
 
After just monkeying with EVERYTHING I eventually figured it out. I turned off "Allow Attack Combos" on the Repeat Combo Trigger Action Module Group, and this allowed the recoil substate 20 to fire. It was still too fast but at least playing.

THEN I was able to make all the recoil states in the animator have "Has Exit Time" on all transitions out, forcing the recoil animation to finish and providing a decent enough "stagger" effect.

Worth mentioning is that "Allow Attack Combos" is enabled by default, and is also enabled in the Sword Setup tutorial video, so I just assumed it was necessary for alternating between multiple attacks.
 
To answer the second part of my question, I was able to add the following code to RecoilModule.cs in the CheckForSolidObject() method:
Code:
else if (hitGameObject.layer == LayerMask.NameToLayer("Default"))
{
    return true;
}

...which allows every object in Default to cause a recoil without a RecoilObject component (in my case Default has all the level geometry). This doesn't set the substate index to 20 for some reason, but I found if I set the "Blocked Recoil Item Substate Index" to 0 (which is additive), and the Animator State's substate index to 20 instead, it works for any object in Default, or any object with the RecoilComponent (in case I need one-offs in another layer).

1688185467868.png

However, occasionally the animator will still get "stuck" in a recoil animation state, even though all the animator parameters get cleared. Any idea why that might be? It seems completely random... sometimes it happens on the first recoil, sometimes it takes a hundred or more recoils to occur.
 
Top