I’m having an issue with Blend Tree and Animation Event.
When I trigger a parameter (MeleeFight), Animator enters in a Blend Tree and Blend Tree choose the right Animation to play with 2D Simple Directional. Each Fight Animation has an Animation Event at beginning and calls a function with a specific Integer parameter. It works with my Hero, only Animation Event from Animation that Blend Tree is choosing is called. But with my AI Enemies, all Animation Event from all Direction Animations are called…
I figured it out, it’s because of the blend tree’s trigger condition is blurry, so we can manually transfer your moveX, moveY into 1 or 0 instead of those specific float number, according to the angle of your direction Vector2
Take my topdown 2d 8 direction game’s enemy logic as sample, 22.5 = 360 / 8 / 2, you can also refine these conditions through variable definition & calculation:
public Vector2 getFinalAnimFloat(Vector2 oldDir)
{
float signedAngle = Vector2.SignedAngle(new Vector2(1, 0), oldDir);
if (signedAngle >= -22.5 && signedAngle <= 22.5)
{
return new Vector2(1, 0);
}
else if (signedAngle >= 22.5 && signedAngle <= 67.5)
{
return new Vector2(1, 1);
}
else if (signedAngle >= 67.5 && signedAngle <= 112.5)
{
return new Vector2(0, 1);
}
else if (signedAngle >= 112.5 && signedAngle <= 157.5)
{
return new Vector2(-1, 1);
}
else if (signedAngle >= 157.5 || signedAngle <= -157.5)
{
return new Vector2(-1, 0);
}
else if (signedAngle >= -67.5 && signedAngle <= -22.5)
{
return new Vector2(1, -1);
}
else if (signedAngle >= -112.5 && signedAngle <= -67.5)
{
return new Vector2(0, -1);
}
else if (signedAngle >= -157.5 && signedAngle <= -112.5)
{
return new Vector2(-1, -1);
}
else return Vector2.zero;
}