I’m trying to set up sword fighting animations using triggers and, while I’m not getting any errors… nothing happens, either. I’m using layers in Mechanim because the player character may have a gun or fists instead of blades and I’m setting the layer weight to 1.0 and I’m using Additive, since I’m also using a layer mask and I’m only animating the upper body with this layer. I think that’s the correct way of doing things, please correct me if I’m wrong. Either way, I’ve tried both Additive and Override and neither work.
Here’s the code I’m using to activate the triggers. The debug lines do execute.
if (Input.GetButtonUp("Fire1"))
{
Debug.Log("SwingLeft");
anim.SetTrigger("SwingLeft");
}
if (Input.GetButtonUp("Fire2"))
{
Debug.Log("SwingRight");
anim.SetTrigger("SwingRight");
}
if (Input.GetButton("Fire3"))
{
Debug.Log("Block");
anim.SetTrigger("SwordBlock");
}
if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
Debug.Log("Slash");
anim.SetTrigger("Slash");
}
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
Debug.Log("Thrust");
anim.SetTrigger("Thrust");
}
Could someone tell me what I’m doing wrong here? This is the first time I’m working with Mechanim layers and, according to the tutorial videos and documentation I’ve seen, this should be working. I’m sure I’m missing something somewhere.
Sorry I didn’t reply to your other thread carnivoris.
So the animations are just playing through without being interrupted?
Are your animations set with has exit time? I have gone through this process only once before, and I no-code, but check to make sure the animations are interrupt-able by either having has exit time is checked or not. It’s a little backwards in my opinion, I believe you want to un-check has exit time for this to work properly, but it might be need to be checked for it to work properly.
No, the animations just aren’t playing, at least, they weren’t when I made this post. I’ve since noticed some errors in my rigs on those animations and corrected those. However, now some of them do play when triggered… but only once. Some of them still don’t play at all. I’ve got a fairly confusing mess on my hands here and I feel like it should be fairly simple.
I actually don’t understand what the person in that link is trying to do, really. The videos and documentation I’ve been looking at does pretty much exactly what I’m trying to do by just using animator.SetLayerWeight and using an avatar mask. I have made some progress today with it. As I said, I’ve gotten it to the point where one animation will play. I’m going to go back over all my animations to make sure they’re set up exactly the same, as far as the rig goes. Maybe that will eventually lead me to a solution.
I do now have another question, though. Do you have to “reset” a trigger? The documentation on Mecanim triggers implies that once you use a trigger, it does it’s action then resets on its own. However, in this particular instance, it seems to trigger once and then not want to trigger again. I need to find out why.
Trigger reset them self when they are consummed by a transition.
The behaviour that you see is often caused by the game loop ifset. You set the trigger in your Update function, the engine evaluate the mecanim controller which consumme your trigger, then you get another MonoBehaviour.Update and the button is still press so you set your trigger back to true.
if (Input.GetButton("Fire3")) anim.SetTrigger("SwordBlock");
}
Input.GetButton return true as long as the button is pressed, Autofire and trigger doesn’t work well together you should maybe use Input.GetButtonDown in this case