Having problems attacking while moving at the same time with sprites 2d

as the title says, i cant seem to get it to work, let alone i cant find any tutorials, nor can i find any docs or info on the site to suggest that this is even possible.

i tried using the animation blending system, and put it on a different animation layer, but that didnt work.

what i am trying to do specifically is say:

// attack while walking, IE: swing sword while moving, or shoot while moving
if(walkedbuttonpressed && attackbuttonpressed){
anim.SetBool(“Walking”,true);
Movestuffhere();
anim.SetBool(“Attacking”,true);
AttackStuffhere();
}

this code should let my character move and attack at the same timeish.

so my character will not attack nor will it move with this code. these are 2dsprites that im using.

thanks for any help or info.

1 Like

If you don’t have sprites that show the character swinging a sword while walking, I don’t think Unity can work magic to make that happen. If you have sprites that show him walking, and other sprites that show him swinging the sword, those two actions are separate and I don’t think the blending stuff can do what you want it to. That can help smooth the transition BETWEEN walking and swording, but not blend the two into a new action.

Jay

1 Like

I’m working on the same issue. Unity doesn’t allow me to move.jump and fire at the same time. 2D anyway. I never had this issue with 3D.

I am going to be adding an attack animation to my 2D game soon. My plan was to have separate attack animations for when the player is not moving and for when the player is moving. For example, attack_idle will transition from the idle state in the animator if the player is not moving and is attacking.

Hopefully this gives you some ideas for your project.

-Nate

1 Like

If your character is wielding say a sword you could split your sprite into the character sprite and an arm + sword sprite and combine the object using both. You could then animate both independently.

Come to find out my issue was my touch pad driver on my laptop. My left click doesn’t work when I’m pressing a key. Sux! However, the good news is that plugging a mouse up resolves the issue.