I'm fiddling around with a 2D side-scroll game using C# in Unity. Basically, I have a method that gets called when I hit an animation trigger on the animator and that method instantiates a GameObject (in my case, an arrow) that has force applied to it. Everything is working good and error free with the exception that I am getting 2 arrows spawning at once. I did some digging and found that my method that instantiates the arrow GameObject is running twice because of my blend tree shown here: enter image description here

[As you can see, the blend between two animations causes the trigger to be called from each one; thus causing 2 object instances.]

[I have attack triggers on each "ArcherFire" animation because it should launch an arrow in any of the 4 positions of 30 degrees, 60 degrees, 90 degrees, and 120 degrees.]

enter image description here

The blend tree is based on the mouse position and it works well enough:

public void GetArcherAngle() { Vector2 mouseVector = Input.mousePosition; float mousePosition = mouseVector.y / Screen.height; animator.SetFloat("BlendTree", mousePosition); } 

As I said before, I have no issues with the code or anything like that. I've tried booleans but had mixed results. The thing with having "if" statements with a float range for mouse positions is they seem to change to the left or right and fall off of the float range for that specific archer angle. It isn't consistent enough.

So, my question is, what is the best way to handle switching from one animation to another in the blend tree without calling the trigger on both? I'm still learning my way around a bit so I'm curious about something maybe I haven't learned about yet.

Thanks for your time.

1 Reply 1

I think the best would be to separate the angle from the shooting animation into two separate animator layers .. the angle should only affect the angle nothing else. And then there would be a single animation for doing the shooting itself and have the trigger. See Animation Layers

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.