For my Unity 2d platformer, I made a melee attack animation that has a trigger (Attack) that is activated when the player presses x on the keyboard. I then tried to create a version of the animation that plays when turned left (controlled by float TurnDirection being less than 0), and that has not worked. I included the conditions and yet, even when I could visibly see both were checked to be at the right conditions, nothing. Upon further inspection, I found that because the WalkingLeft animation plays at the same time, it is stopping the AttackLeft animation from playing. However, when I preview it everything is fine. It’s just making it work in the actual game that is the problem. I then placed it on a separate layer only to find out that now the regular attack animation isn’t working either. I am using Unity 2D, with pixel art models. From looking around in Discussions, I could only see these sorts of issues with 3D modelling and animation. The jumping and landing animations on the left side do not work either, yet the right side versions of each of these work exactly as they should.
You could do a function where your character sprite flips, so you dont need seperate animations for attacking left or right.
public SpriteRenderer sprite;
void Start()
{
}
void Update
{
PlayerDirection();
}
void PlayerDirection()
{
if (xInput < 0)
{
sprite.flipX = true;
}
if (xInput > 0)
{
sprite.flipX = false;
}
}
I had a character with separate arms that are animated independently from the sprite, and I tried that strategy with flipping the SpriteRenderer until figuring out that the arms were not included in the flip, but a character without the complex arms would have turned around. I later figured it out on my own by rearranging the animations and the transitions between them. Thank you for the help.